#47665 [Bgs]: Closure as object property not directly executable
ID: 47665
User updated by: al dot james at gmail dot com
Reported By: al dot james at gmail dot com
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Mac OS 10.5
PHP Version: 5.3.0beta1
New Comment:
Ok, so maybe its a desired feature (to fix what goes against
intuition).
Is there any way to register a desired feature?
Previous Comments:
------------------------------------------------------------------------
[2009-03-18 23:27:59] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
------------------------------------------------------------------------
[2009-03-15 19:22:46] al dot james at gmail dot com
Description:
------------
If I assign an instance of the Closure object as a property of an
object, I would expect to be able to execute that property as a
function.
E.g.
$o = new stdClass;
$o->test = function(){
echo "Executing function";
};
I would expect this to work:
$o->test();
However, it does not. This does:
call_user_func($o->test);
The $o->test() syntax is more concise and in keeping with other
languages with such features.
Reproduce code:
---------------
$o = new stdClass;
$o->test = function(){
echo "Executing function";
};
$o->test();
Expected result:
----------------
Executing function
Actual result:
--------------
PHP Fatal error: Call to undefined method stdClass::test()
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47665&edit=1
Thread (3 messages)