bsmither Posted April 20, 2020 Share Posted April 20, 2020 After switching from PHP 5.3 on Windows Server 2003 to PHP 7.4.3 on Linux Mint 19.3 (Tricia Cinnamon), I find that the output of print_r() has changed. If we look at the documentation (https://www.php.net/manual/en/function.print-r.php), the provided example output is as it was on my earlier machine: <pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) </pre> However, on the second machine, the output is: <pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) <blank line> ) </pre> Note the unexpected new line after each recursed array's closing parenthesis. The new line is not present after the outermost array closing parenthesis. Also to note, there is a newer version of XDebug installed. My question is: Is this a bug? (Follow-on question: if possible to determine at which version the output changed, what version would that be?) This difference is causing existing code to not be able to correctly parse that output. Quote Link to comment Share on other sites More sharing options...
chhorn Posted April 20, 2020 Share Posted April 20, 2020 print_r is just a debug function without any format expectations. parsing this is mostly wrong. use a proper data exchange format. 1 Quote Link to comment Share on other sites More sharing options...
StevenOliver Posted April 21, 2020 Share Posted April 21, 2020 Same thing when I tried it, too. If you don't like blank lines, you could try var_export($array) instead of print_r($array) Quote Link to comment Share on other sites More sharing options...
bsmither Posted April 21, 2020 Author Share Posted April 21, 2020 I wouldn't know what to look for when searching PHP's bug tracking system. That's why I asked here - maybe there is someone here who is far, far more into understanding the innards of PHP who could definitely say the extra line endings is a bug, and whether or not it is even directly associated with print_r(), or if the extra line endings were coded into the PHP source elsewhere and its appearance in print_r() is a knock-on effect. Â Quote Link to comment Share on other sites More sharing options...
Barand Posted April 21, 2020 Share Posted April 21, 2020 Why are you trying to get your data from print_r() output in the first place? 1 Quote Link to comment Share on other sites More sharing options...
chhorn Posted April 21, 2020 Share Posted April 21, 2020 It's not a bug, parsing print_r is not an inteded feature. if you still think it's a bug, you can just open an issue in the bugtracker, but i bet you get a similar answer. Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 21, 2020 Share Posted April 21, 2020 On 4/20/2020 at 2:25 AM, bsmither said: This difference is causing existing code to not be able to correctly parse that output. Your doing something wrong. Code should not be parsing print_r. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.