S
S
Sergey Pugovkin2018-04-02 18:52:20
PHP
Sergey Pugovkin, 2018-04-02 18:52:20

Why does var_export "frame" null bytes with empty strings?

<?php
echo var_export("\0", true);

Issues:
'' . "\0" . ''
Why? Why not just
"\0"
?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2018-04-02
@Driver86

You assume too smart logic for a stupid function.
https://github.com/php/php-src/blob/PHP-7.2/ext/st...
var_export tries to output a string in single quotes so that special characters and other goodies are not substituted in it. But null-byte therefore cannot be displayed in single quotes. Therefore, all \0 are replaced with ' . \"\\0\" . '
In the extreme case, just single quotes are obtained at the edges of the resulting string and ' . \"\\0\" . ' as the main data. And checking beforehand that we only have \0 in the string is too special a case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question