Req #48154 [Opn->Sus]: Add optional paramter to print_r() for basic (X)HTML output formatting

From: Date: Fri, 18 Sep 2020 14:51:19 +0000
Subject: Req #48154 [Opn->Sus]: Add optional paramter to print_r() for basic (X)HTML output formatting
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229075@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48154&edit=1 ID: 48154 Updated by: cmb@php.net Reported by: stepheneliotdewey at gmail dot com Summary: Add optional paramter to print_r() for basic (X)HTML output formatting -Status: Open +Status: Suspended Type: Feature/Change Request Package: Variables related Operating System: irrelevant PHP Version: 5.2.9 Block user comment: N Private report: N New Comment: Introducing this feature appears to be controversial (see my earlier comment above), and as such requires discussion which is beyond the scope of this bug tracker. If you are still interested in this, please send mail to the PHP internals mailing list[1]. For the time being, I'm suspending this ticket. [1] <https://www.php.net/mailing-lists.php#internals> Previous Comments: ------------------------------------------------------------------------ [2015-05-02 12:03:28] cmb@php.net You could write an own function to format the output: function print_r_html($val) { echo '<pre>', htmlspecialchars(print_r($val, true)) , '</pre>'; } Another option would be to use var_dump(), which gives a nicely formatted and syntax highlighted output when Xdebug is installed. ------------------------------------------------------------------------ [2009-05-05 17:18:34] stepheneliotdewey at gmail dot com Description: ------------ Output of print_r() is often viewed in a web browser, but in this setting, objects are rendered as long strings that are hard to read, because they have lots of properties, nested objects, etc. It is much easier to view such output by viewing page source (i.e. actual PHP output), since that will take into account newlines/whitespace characters that are ignored by (X)HTML browsers. However, it would be nice to have an optional parameter to make print_r() format its output for a browser (e.g. maybe <div>'s with inline CSS padding to force indentation, or at least <br /> and &nbsp;). Since print_r() is primarily a debugging tool, this could be pretty handy during development, and could encourage greater adoption of OOP practices. ALTERNATIVELY, a tip should be added to the print_r() documentation page telling users that arrays and objects printed by print_r() can be viewed more easily by looking directly at the source of the output, rather than through a browser. Reproduce code: --------------- N/A, see above. Expected result: ---------------- N/A, see above. Actual result: -------------- N/A, see above. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=48154&edit=1

« previous php.bugs (#229075) next »