Bug #53573 [Com]: Invisible "static" property of Closure

From: Date: Wed, 16 Feb 2011 01:04:21 +0000
Subject: Bug #53573 [Com]: Invisible "static" property of Closure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-158803@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53573&edit=1

 ID:                 53573
 Comment by:         olamedia at gmail dot com
 Reported by:        kak dot serpom dot po dot yaitsam at gmail dot com
 Summary:            Invisible "static" property of Closure
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 PHP Version:        5.3.4
 Block user comment: N
 Private report:     N

 New Comment:

Please, let Closure be standard object without any restrictions.
Let developers decide what they can use, and what must not.
PHP is already full enough of "RESERVED" "YOU MUST NOT" "YOU CAN NOT"
"YOU SHOULD 
NOT" "ITS HARD, SO WE WILL NOT MAKE THIS FEATURE" "I DONT NEED THIS, SO
PLEASE 
DON'T REQUEST THIS FEATURE"


Previous Comments:
------------------------------------------------------------------------
[2011-02-16 01:51:07] olamedia at gmail dot com

<?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');

------------------------------------------------------------------------
[2010-12-19 06:03:08] 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



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53573&edit=1


Thread (5 messages)

« previous php.bugs (#158803) next »