The real problem is: yes, PHP syntax has lack of support fur such situation. Neither {..}
nor (..)
may help you. The only way to access the property (without __call()
magic) is:
class testing {
public $testvars;
function __construct(){
$this->testvars = function(){
return "Test String";
};
}
}
$obj = new testing();
echo call_user_func_array($obj->testvars, []);
So to pass your callback into call_user_func_array()
. Note big difference with passing of [$obj, 'testvars']
(which won't work here, obviously) - since your property contains a callback, but not class contains such method. You may also use call_user_func()
of course.
As for syntax support, there is an RFC which is proposed by Nikita Popov and which will allow you to resolve the issue with syntax only - so no additional function calls would be needed (Fortunately, that RFC was accepted and has real chances to be implemented in newer PHP versions).