Exam 200-710 All QuestionsBrowse all questions from this exam
Question 5

What is the output of the following code?

    Correct Answer: B

    In PHP, when an object is cast to an array, only the public properties of the object are included in the resulting array with their respective keys. Private properties are excluded. In the given code, class Bar has a private property $a and a public property $c. When the object of class Bar is cast to an array, only the public property $c will be part of the array with the key 'c'. The array will not include the private property $a. As a result, checking if the key 'a' exists in the array will return false, and checking if the key 'c' exists will return true. Therefore, the output is false-true.

Discussion
buiphuc

In the class, public variables will be converted into corresponding keys. Protected and private variables are not