php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47665 Closure as object property not directly executable
Submitted: 2009-03-15 19:22 UTC Modified: 2009-03-19 08:10 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: al dot james at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0beta1 OS: Mac OS 10.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: al dot james at gmail dot com
New email:
PHP Version: OS:

 

 [2009-03-15 19:22 UTC] 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()

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-18 23:27 UTC] 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-19 08:10 UTC] al dot james at gmail dot com
Ok, so maybe its a desired feature (to fix what goes against intuition). 
Is there any way to register a desired feature?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 10:01:34 2025 UTC