You have two classes (Class1 and Class2). Class1 calls a non static
Class2 function with a Class2 variable assignment, but without a return
value. The value set in Class2 is somehow assigned to Class1. If the
function was set to static or the class is instantiated the problem does
not occur. See code example below for better explanation... I submitted a bug report to PHP, but maybe I was wrong and theres a logical explanation?
// Causes unexpected results
class Class1 {
public function __construct() {
Class2::dosomething();
}
}
class Class2 {
private $somevar;
public function dosomething() {
$this->somevar = 'test';
}
}
$x = new Class1();
print_r($x);
You should see:
Class1 Object ( )
But instead you see:
Class1 Object
(
[somevar] => test
)