|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-12-19 06:03 UTC] kak dot serpom dot po dot yaitsam at gmail dot com
Description:
------------
var_dump($closure) displays public property named "static", but I cannot access to
it with standard call: Closure object cannot have properties
It might be very useful!
Thanks.
Test script:
---------------
<?php
$a = function() {
static $foo = 'bar';
echo $foo."\n";
};
var_dump($a);
$a->{'static'}['foo'] = 'foo';
$a();
Expected result:
----------------
Output: foo
Actual result:
--------------
object(Closure)#1 (1) {
["static"]=>
array(1) {
["foo"]=>
string(3) "bar"
}
}
PHP Catchable fatal error: Closure object cannot have properties in
/home/web/1.php on line 7
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 05:00:01 2025 UTC |
<?php class a{ public $c = array(); function __call($name, $args){ $closure = $this->c[$name]; // example $self = $this; // how can I pass $self to closure? $closure->static['self'] = $this // NO!, Reflection is giving empty array call_user_func_array($closure, $args); } } $a = new a(); $a->c['hello'] = function($x) use ($self){ return 'Hello, '.$x.'! My name is '.get_class($self).'!'; }; $a->hello('php');