PHP Casting as Object type in foreach Loop
Posted
by
Coulton
on Stack Overflow
See other posts from Stack Overflow
or by Coulton
Published on 2012-09-13T15:36:33Z
Indexed on
2012/09/13
15:37 UTC
Read the original article
Hit count: 177
Within the following code, $quiz_object->personalities
contains an array of Personality()
objects.
// Loop through each personality that exists for the quiz
foreach($quiz_object->personalities AS $existing_personality)
{
// Show all of the existing personalities
echo $existing_personality->GetQuizMakerPersonalityHTML();
}
How do I "cast" (I think that's the right word) my variable $existing_personality
within the foreach loop as the object type?
I wish to do this so that when I type $existing_personality->
, I get the list of public functions available for that object type.
At the moment, Zend doesn't know that it refers to a Personality
object within the loop.
© Stack Overflow or respective owner