Edit report at https://bugs.php.net/bug.php?id=64554&edit=1
ID: 64554
Comment by: hanskrentel at yahoo dot de
Reported by: cornelius dot howl at gmail dot com
Summary: var_export does not export absolute namespace for
classname
Status: Open
Type: Bug
Package: Documentation problem
Operating System: Any
PHP Version: 5.4.13
Block user comment: N
Private report: N
New Comment:
Can you add the code where you run into that issue? I could not reproduce this
with eval(return var_export();) across different namespaces.
http://3v4l.org/3MhAf#v530
Previous Comments:
------------------------------------------------------------------------
[2013-04-15 10:23:34] laruence@php.net
change to doc bug, see: http://marc.info/?l=php-internals&m=136599465400822&w=2
------------------------------------------------------------------------
[2013-03-31 12:19:54] laruence@php.net
I think similar issue also exists in serialize...
------------------------------------------------------------------------
[2013-03-31 09:48:23] laruence@php.net
hmm, I feel this probably make sense, simply add a lead '\\' solve the problem:
diff --git a/ext/standard/var.c b/ext/standard/var.c
index f76a14c..67a0a72 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -485,6 +485,7 @@ PHPAPI void php_var_export_ex(zval **struc, int level,
smart_str *buf TSRMLS_DC)
}
Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name,
&class_name_len, 0 TSRMLS_CC);
+ smart_str_appendc(buf, '\\');
smart_str_appendl(buf, class_name, class_name_len);
smart_str_appendl(buf, "::__set_state(array(\n", 21);
but not sure the side-affect, need more testing
------------------------------------------------------------------------
[2013-03-31 05:55:28] cornelius dot howl at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.var-export#refsect1-function.var-
export-description
---
If I defined a class "Foo\Bar\C" that implements __set_state method, then use
var_export to export the php code, and put this exported code to another
namespace, it will causes "class not found".
because the exported class name is "Foo\Bar\C" not "\Foo\Bar\C", the class can
not
be found without the root namespace. :(
var_export should always export the root namespace.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64554&edit=1