You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interesting. I confirm this on 3v4l.org in all supported versions. Number of iterations need to be at least 10000 to notice the memory usage difference (1000000 is too big there).
var_export uses a string builder internally that allocates a buffer a bit larger than necessary while building the string. The issue here is that the string is not copied to a smaller buffer at the end.
The cast to string does nothing when the value is already a string. The concatenation however will force the string to be reallocated, and will use the minimum amount of memory.
Description
The following code:
Resulted in this output:
But this code with var_export casted to "real" string:
Resulted in this output:
What kind of magic is working here ?
PHP Version
PHP 7.4
Operating System
Ubuntu
The text was updated successfully, but these errors were encountered: