<?php
Class MyClass
{
private $prop1 = "foo";
private $prop2 = "bar";
public function func1()
{
global $prop1;
global $prop2;
// by declaring global variables inside this method, it works!
echo $prop1;
}
}
$bj1 = new MyClass();
$obj1->func1();
Warning: Undefined variable $obj1 in /in/0Z2up on line 19
Fatal error: Uncaught Error: Call to a member function func1() on null in /in/0Z2up:19
Stack trace:
#0 {main}
thrown in /in/0Z2up on line 19
Process exited with code 255.
Notice: Undefined variable: obj1 in /in/0Z2up on line 19
Fatal error: Uncaught Error: Call to a member function func1() on null in /in/0Z2up:19
Stack trace:
#0 {main}
thrown in /in/0Z2up on line 19
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.26
Fatal error: Uncaught Error: Call to a member function func1() on null in /in/0Z2up:19
Stack trace:
#0 {main}
thrown in /in/0Z2up on line 19
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Notice: Undefined variable: obj1 in /in/0Z2up on line 19
Fatal error: Uncaught Error: Call to a member function func1() on unknown in /in/0Z2up:19
Stack trace:
#0 {main}
thrown in /in/0Z2up on line 19
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Notice: Undefined variable: obj1 in /in/0Z2up on line 19
Fatal error: Call to a member function func1() on null in /in/0Z2up on line 19
Process exited with code 255.
Notice: Undefined variable: obj1 in /in/0Z2up on line 19
Fatal error: Call to a member function func1() on a non-object in /in/0Z2up on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: obj1 in /in/0Z2up on line 19
Fatal error: Call to a member function func1() on a non-object in /in/0Z2up on line 19
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/0Z2up 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/0Z2up 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/0Z2up on line 5
Process exited with code 255.