Skip to content

Commit

Permalink
Removed warning about missing namespace leading backslash in `var_exp…
Browse files Browse the repository at this point in the history
…ort()` docs

`var_export()` needs to prefix classes it references with `\`, because its code could be transplanted in
any source location/namespace, so the assumption of it being used only in the context of the root
namespace is not sufficient.

For example, in a code snippet like following ( https://3v4l.org/4mONc ):

```php
<?php

class SomeObject {}
var_export([new SomeObject]);
```

This should produce:

```
array (
  0 => 
  \SomeObject::__set_state(array(
  )),
)
```

Userland should not concern itself with the contents of the `var_export()`-produced code
snippets, and use them as-is instead.

Ref: php/php-src#8232
Ref: php/php-src#8233
Ref: Ocramius/ProxyManager#754
  • Loading branch information
Ocramius authored Mar 21, 2022
1 parent 59af099 commit 6f0a58d
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions reference/var/functions/var-export.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,6 @@ object(A)#2 (2) {
or object, use <function>serialize</function>.
</para>
</note>
<warning>
<para>
When <function>var_export</function> exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility.
</para>
</warning>
<note>
<para>
To be able to evaluate the PHP generated by <function>var_export</function>,
Expand Down

0 comments on commit 6f0a58d

Please sign in to comment.