I have been trying to move some legacy code into Symfony2 but have come to something which has stumped me. I have a function
public function findSeatsOnFlights($allInfo, $flights, $seatCodes)
{
}
In both the legacy and my new code, $allInfo is the same format so do not need to worry about this. In my legacy code, if I var_dump $flights and $seatCodes, I get something like
array(2) {
[0]=> string(3) "VS7"
[1]=> string(3) "VS8"
}
array(2) {
[0]=> string(1) "C"
[1]=> string(1) "D"
}
To handle this, I would do
public function findSeatsOnFlights($allInfo, $flights, $seatCodes){
$answer = array( );
foreach ( $flights as $flight )
{
$finfo = $allInfo[ $flight ];
$fseats = $finfo["seats"];
foreach ( $seatCodes as $code )
{
}
}
}
However, with Symfony2, my var_dump of $flights and $seatCodes is
array (size=2)
0 =>
object(stdClass)[405]
public '__CLASS__' => string 'Nick\AlertBundle\Entity\AvailabilityAlertFlightNumbers' (length=55)
public 'id' => int 52
public 'flightNumber' => string 'VS7' (length=3)
public 'availabilityAlert' => string 'Nick\AlertBundle\Entity\AvailabilityAlert' (length=42)
1 =>
object(stdClass)[406]
public '__CLASS__' => string 'Nick\AlertBundle\Entity\AvailabilityAlertFlightNumbers' (length=55)
public 'id' => int 53
public 'flightNumber' => string 'VS8' (length=3)
public 'availabilityAlert' => string 'Nick\AlertBundle\Entity\AvailabilityAlert' (length=42)
array (size=2)
0 =>
object(stdClass)[406]
public '__CLASS__' => string 'Nick\AlertBundle\Entity\AvailabilityAlertBookingClass' (length=54)
public 'id' => int 62
public 'classLetter' => string 'C' (length=1)
public 'availabilityAlert' => string 'Nick\AlertBundle\Entity\AvailabilityAlert' (length=42)
1 =>
object(stdClass)[404]
public '__CLASS__' => string 'Nick\AlertBundle\Entity\AvailabilityAlertBookingClass' (length=54)
public 'id' => int 63
public 'classLetter' => string 'D' (length=1)
public 'availabilityAlert' => string 'Nick\AlertBundle\Entity\AvailabilityAlert' (length=42)
So how would I go about handling this instead? I have tried things like this without success
foreach ( $flights as $flight )
{
$finfo = $allInfo[ $flight->getFlightNumber() ];
....
If I do the above I get
Warning: Illegal offset type (500 Internal Server Error)
So what is the best way of changing my code to now handle the Objects?