|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-09-06 10:36 UTC] dexen dot devries at gmail dot com
Description:
------------
While var_dump() produces sensible output for Closures, output of the var_export() is pretty much useless.
Test script:
---------------
<?php
$a = range(1, 3);
$foo = function($n) use($a) {
return $a[$n];
};
var_dump($foo);
var_export($foo);
Expected result:
----------------
object(Closure)#1 (2) {
["static"]=>
array(1) {
["a"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
["parameter"]=>
array(1) {
["$n"]=>
string(10) "<required>"
}
}
(((resembling the following:)))
object(Closure)#1 (2) {
["static"]=>
array(1) {
["a"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
["parameter"]=>
array(1) {
["$n"]=>
string(10) "<required>"
}
}
Actual result:
--------------
object(Closure)#1 (2) {
["static"]=>
array(1) {
["a"]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
["parameter"]=>
array(1) {
["$n"]=>
string(10) "<required>"
}
}
Closure::__set_state(array(
))
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 18:00:01 2025 UTC |
This would be great. Could the parameter list and PHP code defined in the closure be passed to __set_state()? Something like: function ($a, $b) { return 'hi'; } __set_state(array( 'parameters' => array( 'a' => array( ... ) 'b' => array( ... ) ), 'code' => 'return \'hi\';' )); It might be tricky to export the use()d variables, though.