<?php
class A
{
protected $a = 0;
public function printCount()
{
print $this -> a;
print PHP_EOL; // print a new line.
}
}
class B
{
public $b = 0;
public function doSomethingWith( $a )
{
$a -> a++;
}
}
$a = new A();
$b = new B();
$a -> printCount();
$b -> doSomethingWith( $a );
$a -> printCount();
0
Fatal error: Uncaught Error: Cannot access protected property A::$a in /in/JY4qT:20
Stack trace:
#0 /in/JY4qT(27): B->doSomethingWith(Object(A))
#1 {main}
thrown in /in/JY4qT on line 20
Process exited with code 255.
0
Fatal error: Cannot access protected property A::$a in /in/JY4qT on line 20
Process exited with code 255.
Output for 5.0.0 - 5.0.1
0
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/JY4qT on line 10
PHP_EOL
Fatal error: Cannot access protected property A::$a in /in/JY4qT on line 20
Process exited with code 255.
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/JY4qT on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/JY4qT on line 5
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/JY4qT on line 5
Process exited with code 255.