Hi Dusk, > There's an interesting edge case where this does become useful. If an > evaluable representation of a data structure is written to a file (wrapped > with `<?php return $x;`) and subsequently loaded using `require()`, the file > can be stored in opcache. This is dramatically faster than unserialize() or > json_decode(), especially for large structures. > > What'd be particularly useful for this use case would be a function which > behaved similarly to `var_export()`, but which didn't pretty-print its > output, so as to yield a smaller file.
The larger benefit is readability and that you could reindent the output or change the line endings in the output (automatically or manually through your IDE) without worrying about accidentally changing the representation. ``` // or other classes const SER = array ( 0 => 'O:8:"stdClass":1:{s:7:"headers";s:20:"Content-Length: 10 ";}', ); ``` The size on disk would be smaller and I expect the encoding and saving a file to disk could be a tiny bit faster, but the size in opcache would be unchanged because the resulting array is the same. For the question of size, you'd still benefit in cases where representation size (e.g. megabytes of large/nested configuration or generated data) is a concern and may or may not get a small speedup when loading the file for the first time after clearing opcache (e.g. server restart). (haven't benchmarked it) Cheers, - Tyson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php