#41380 [Opn->Bgs]: Unable to store lambda-style functions in object properties.

From: Date: Mon, 14 May 2007 12:32:09 +0000
Subject: #41380 [Opn->Bgs]: Unable to store lambda-style functions in object properties.
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969376317@lists.php.net to get a copy of this message
ID: 41380 Updated by: colder@php.net Reported By: stosh1985 at gmail dot com -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Mac OS X PHP Version: 5.2.2 New Comment: His issue is not about default values, by the way, a "lambda-style function" is only a callback, being a string here. However, your problem comes from the fact that $object->property() is parsed as if property was a method. You'd have to either use $tmp = $this->method; $tmp('a', 'b'); or call_user_func() / call_user_func_array(). No documentation problem here. Previous Comments: ------------------------------------------------------------------------ [2007-05-14 02:37:31] judas dot iscariote at gmail dot com http://php.net/manual/en/language.oop5.basic.php "The default value must be a constant expression, not (for example) a variable, a class member or a function call." This is the expected behaviuor.. a lambda style function is not a constant expression. ------------------------------------------------------------------------ [2007-05-12 20:51:28] stosh1985 at gmail dot com Description: ------------ I am unable to store lambda-style function within object properties, like I am with normal variables. The below code does not work, neither does calling $this->$method() or using call_user_func() with passing in array($this, $this->method) for the callback. Reproduce code: --------------- <?php class foo { public $method; function __construct() { $this->method = create_function('$a, $b', 'print $a . "\n" . $b . "\n\n"; '); $this->method('a', 'b'); } } $x = new foo(); $x->method('a', 'b'); ?> Expected result: ---------------- a b a b Actual result: -------------- Fatal error: Call to undefined method foo::method ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41380&edit=1

« previous php.doc (#969376317) next »