|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-05-12 20:51 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 13:00:01 2025 UTC |
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.