I can’t find the reason in the documentation why this code works fine in 7.0.5:
<?php class A { private static $a; function __construct() { self::$a = new B; echo "1. ".__CLASS__.' '.self::$a->b."\n"; self::$a->b = 'A::test'; //7.0.5 ok echo "2. ".__CLASS__.' '.self::$a->b."\n"; echo self::$a; // ok expected } public static function test() { return 'ok'; } } class B { public $b; public function __toString() { echo "3. ".__CLASS__.' '.$this->b."\n"; $tmp = $this->b; echo "4. ".__CLASS__.' '.$tmp.' '.is_string($this->b).' '.is_callable($this->b)."\n"; $res = $tmp(); echo "5. ".__CLASS__.' '.$res."\n"; return $res; } } $a = new A; Result:
1. A 2. AA::test 3. BA::test 4. BA::test 1 1 5. B ok ok And it gives an error for 5.6.2 "Call to undefined function A :: test ()" on the line $ res = $ tmp ()?
Result:
1. A 2. AA::test 3. BA::test 4. BA::test 1 1 Fatal error: Call to undefined function A::test() If you use call_user_func instead of $ res = $ tmp () - everything works, but I really want to access the function through a variable. Maybe? I ask for help and knowledge.