3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class InCommon { private $baz = 'foo'; public function out($pref){ echo "\n".$pref.'::$baz = '.$this->baz; } } class Foo extends InCommon { public function peek($target, $pref){ echo "\n".'peek @'.$pref.'::$baz = '.$target->baz; } } class Bar extends InCommon { public function peek($target, $pref){ echo "\n".'peek @'.$pref.'::$baz = '.$target->baz; } public function mess($target){ $target->baz = 'cats'; } } $foo = new Foo(); $bar = new Bar(); echo "Messing with variable"; $bar->mess($foo); // bar messes with foo's baz, which should be private echo "\nFoo looks at its own $baz:"; $foo->out('Foo'); // foo looks at its own baz, which remains unchanged echo "\nBar looks at Foo's $baz:"; $bar->peek($foo, 'Foo'); // yet when bar looks at foo's baz (which is shouldn't see) we get the change from above echo "\n\nFoo can't look at Bar's $baz"; $foo->peek($bar, 'Bar');
based on 3goak
Output for 5.2.6 - 7.1.0
Messing with variable Notice: Undefined variable: baz in /in/c3Q9E on line 26 Foo looks at its own : Foo::$baz = foo Notice: Undefined variable: baz in /in/c3Q9E on line 28 Bar looks at Foo's : peek @Foo::$baz = cats Notice: Undefined variable: baz in /in/c3Q9E on line 31 Foo can't look at Bar's Notice: Undefined property: Bar::$baz in /in/c3Q9E on line 10 peek @Bar::$baz =
Output for 5.0.4 - 5.2.5
Messing with variable Notice: Undefined variable: baz in /in/c3Q9E on line 26 Foo looks at its own : Foo::$baz = foo Notice: Undefined variable: baz in /in/c3Q9E on line 28 Bar looks at Foo's : peek @Foo::$baz = cats Notice: Undefined variable: baz in /in/c3Q9E on line 31 Foo can't look at Bar's Notice: Undefined property: Bar::$baz in /in/c3Q9E on line 10 peek @Bar::$baz =
Output for 5.0.0 - 5.0.3
Messing with variable Notice: Undefined variable: baz in /in/c3Q9E on line 26 Foo looks at its own : Foo::$baz = foo Notice: Undefined variable: baz in /in/c3Q9E on line 28 Bar looks at Foo's : peek @Foo::$baz = cats Notice: Undefined variable: baz in /in/c3Q9E on line 31 Foo can't look at Bar's Notice: Undefined property: Bar::$baz in /in/c3Q9E on line 10 peek @Bar::$baz =
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/c3Q9E on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/c3Q9E on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/c3Q9E on line 3
Process exited with code 255.