View Full Version : PHP Bug: Property Class __invoke

10-29-2009, 02:42 AM
class a {
function __construct() { }
function __invoke() { echo("Invoked\n"); }

$a = new a();
// Prints: Invoked

class b {
private $x;

function __construct() {
$this->x = new a();

$b = new b();
// Issues error: undefined method b::x

Bug, yes?


10-29-2009, 02:48 AM
Maybe should have mentioned that's on 5.3.0.

On 5.2.11 ionCube/Suhosin I get:

Function name must be a string on line 9

Edit: I'll clarify.

This is important to me because I have a complex self-sanitising database class that has an invoke method. The invoke method takes a sql string, resource or a iterating result class. Lets me do stuff like try { $row = $db($db('query')); } or try { foreach($db('query') as $row) ... } - IF I can get the damn invoke working...

10-29-2009, 03:19 AM
$this->x declares itself as a callable method which refuses to execute and instead focuses on the missing b::x() method. It doesn't really matter which way they sway (I would pass any callback into a method for assignment rather than to declare it within a class), but if this is the route that the PHP team plans to take they will still need to correct that is_callable returns true on it.
I'd say report it anyway.

10-29-2009, 03:35 AM
I have reported it, if only to see what they say ;)