200-550 practice questions, page 7 of 9, with answer review and explanations.
Question 31
What is the output of the following code? class C { public $x = 1; function __construct() { ++$this->x; } function __invoke() { return ++$this->x; } function __toString() { return (string) --$this->x; } } $obj = new C(); echo $obj();
0
1
2
3
Question 32
SIMULATION - Consider the following code. Which keyword should be used in the line marked with "KEYWORD" instead of "self" to make this code work as intended? abstract class Base { protected function __construct() { } public static function create() { return new self(); // KEYWORD } abstract function action(); } class Item extends Base { public function action() { echo __CLASS__; } } $item = Item::create(); $item->action(); // outputs "Item"
Question 33
SIMULATION - Which SPL class implements fixed-size storage?
Question 34
In order to create an object storage where each object would be stored only once, you may use which of the following? (Choose 2)
SplFixedArray
SplObjectStorage
SplString
spl_object_hash
spl_same_object
Question 35
What is the output of the following code? class Base { protected static function whoami() { echo "Base "; } public static function whoareyou() { static::whoami(); } } class A extends Base { public static function test() { Base::whoareyou(); self::whoareyou(); parent::whoareyou(); A::whoareyou(); static::whoareyou(); } public static function whoami() { echo "A "; } } class B extends A { public static function whoami() { echo "B "; } } B::test();