php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55149 Limit the result of print_r() to facilitate debugging
Submitted: 2011-07-06 11:51 UTC Modified: 2017-09-10 21:07 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:0 of 0 (0.0%)
From: victor at cmp dot es Assigned:
Status: Suspended Package: Variables related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
38 - 12 = ?
Subscribe to this entry?

 
 [2011-07-06 11:51 UTC] victor at cmp dot es
Description:
------------
You could add an additional third parameter to print_r() function in order to limit the nesting level of output.
Instead of showing all levels of nested arrays/objects, it could be limited to N nesting levels.
If I only want to know my simple class member variables (with 3 or 4 of them) of an object but the object has members with "references/alias" to other big objects/classes, the screen is filled with a lot of (in this case) useless information.
If I could limit in this case the output to 1 or 2 nesting levels it would be much easier for me to debug.
If this third parameter were ommitted or zero, the whole tree would be shown (as done now).



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-07 02:31 UTC] lenzai2004-dev at yahoo dot com
Why not writing your own custom php function for that purpose ?
Also for debugging var_dump is sometimes more useful than print_r.
 [2012-01-23 22:54 UTC] gmblar+php at gmail dot com
Try xdebug_var_dump http://xdebug.org/docs/all_functions#xdebug_var_dump for a 
limited output.
 [2017-09-10 21:07 UTC] cmb@php.net
-Status: Open +Status: Suspended -Package: Class/Object related +Package: Variables related
 [2017-09-10 21:07 UTC] cmb@php.net
Apparently, this proposal is controversial and as such would
require an RFC, see <https://wiki.php.net/rfc>. Everybody is
welcome to create a respective RFC; if you do so please refer to
this feature request. In the meantime, I'm suspending this ticket.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 04:01:38 2024 UTC