PHP Quiz part 4
Note: This article was originally published at Planet PHP
on 2 November 2010.
It has been a while, but here is part 4 of the PHP Quiz series! A few questions to crack your brain about, or perhaps you know them all? Try them and find out! Also do read the idea behind these quizzes, here: The PHP Quiz series
As always, think of the answer before you execute the code or look it up. Codepad might help you run the examples. You can find round three here.
A
Visibility is key
Now you see me, now you don't
class testClass {A A private $fubar = "rabuf";
A A function test($test) {
A A A A var_dump($test-fubar);
A A }
}
class dummy {
A A function test($test) {
A A A A var_dump($test-fubar);
A A }
}
$object1 = new testClass;
$object2 = new testClass;
$dummy = new dummy;
$object1-test($object1); // Can $object1 see the private property of object1 ?
$object1-test($object2); // Can $object1 see the private property of object2 ?
$dummy-test($object1); // Can $dummy see the private property of object1 ?
A
A
Static, sticky, icky
class test {A public $counter = -1;
A public function increment() {
A A static
Truncated by Planet PHP, read more at the original (another 7009 bytes)


