PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 27th, 2012, 12:37 PM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
Smile A var_dump() & print_r() alternative

Hey guys, I couldn't find a snippet sub-forum, so I guess I'll post it here. I put together dump_r(), which I feel is a much better print_r() & var_dump() combination. It's lightweight, single-file-include, fully css-themeable and extendable for dumping additional object types. It has other features as well (see the repo link). Try it out if you'd like. I'd appreciate bug reports, feature requests, css themes, patches or general feedback. Requires PHP 5.3+, if you're on <5.3, consider this your public shaming.

demo: http://o-0.me/dump_r/
repo: https://github.com/leeoniya/dump_r.php

there are also some additional expand/collapse features if you hold Ctrl/Shift while collapsing and expanding. They're briefly explained in the commit message here .

thanks!

sample output:

Comments on this post
ManiacDan agrees!

Reply With Quote
  #2  
Old November 28th, 2012, 09:46 AM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
Thumbs up

[Update] now installable through Composer

https://packagist.org/packages/leeoniya/dump-r

require: "leeoniya/dump-r": "dev-master"

Reply With Quote
  #3  
Old December 3rd, 2012, 11:25 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,791 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 14 h 53 m 20 sec
Reputation Power: 6112
One thing this doesn't do is gracefully degrade on the command line. If I print_r to a non-browser (flat file, cli) it's going to be hell to try to chunk through your HTML. If $_SERVER['HTTP_USER_AGENT'] isn't set, maybe fall back to a plaintext version.
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #4  
Old December 3rd, 2012, 12:45 PM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
yeah, it'll mess your command line up!

internally, the structure decomposition is separate from the rendering pass. so it's just a matter of writing an additional text rendering func.

the most obvious and lightweight thing that comes to mind for text dumping is to just call var_dump and maybe reformat it slightly. there's no escaping the need for all the extra clutter when you can't rely on colors. of course this path would bypass lots of goodies that the decomposed tree offers.

ultimately, there needs to be a text version. i'm a bit busy now so probably wont get around to it for some time. but feel free to submit pull requests

thanks for the feedback!

Reply With Quote
  #5  
Old December 3rd, 2012, 01:30 PM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
thinking a bit more...

once the text render method is done, the console part should be easy. but there's still no way to do something like print_r does, with explicitly returning the txt representation to write to a file.

i might change the signature a bit to account for this in conjunction with limiting the recursion depth. maybe

PHP Code:
 dump_r($val$expand=1000$depth=1000$ret=false); 

if $ret is set to true, it can be assumed that text is needed perhaps...

Reply With Quote
  #6  
Old December 3rd, 2012, 03:54 PM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
^^ this is now implemented ^^

as a stop-gap until i have time to write a text renderer, the lib will now fall back to plain var_dump() when in cli or when returning output.
Comments on this post
ManiacDan agrees!

Reply With Quote
  #7  
Old December 4th, 2012, 05:19 PM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
okay, the issue was annoying me, so I found some time for this. there are some small caveats and unfinished things still on the todo list.

- multiline strings will get chopped off after the first line by the regex that handles the re-alignment after everything is buffered.
- private and protected properties are not identified as such
- keys are not enclosed in anything (for readability), so leading and trailing whitespace in string keys will not be obvious. i'm assuming this is pretty rare.

there aren't options right now to limit what does and doesnt get displayed, but the planned settings are:
- independently toggle str lengths, arr lengths, subtypes, parenths around lengths + subtypes, enclosing of string keys in single quotes
- key => value dots as horiz guides for easier readability
- more detail for recursion and reference types

that said, i tried to make it as clean and useful as possible and match the html version when possible. recursion depth limiting is supported the same way as in the html output. the var_dump and print_r versions are also included at the bottom of the example.

http://o-0.me/dump_r/example2.php

[UPDATE] if you want to try it out, it's up on a separate branch: https://github.com/leeoniya/dump_r.php/tree/renderTEXT

leon

Last edited by Leeoniya : December 4th, 2012 at 07:30 PM. Reason: mention renderTEXT branch

Reply With Quote
  #8  
Old December 5th, 2012, 12:39 PM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
the text-mode multiline issue (the only serious one) has been fixed. unlike var_dump and print_r, it also aligns the string's individual lines to the correct nesting level.

i merged the renderTEXT branch into master, so this functionality is now official.

the example at http://o-0.me/dump_r/ has also been updated to include text dumps.

Reply With Quote
  #9  
Old January 19th, 2013, 11:51 AM
Leeoniya Leeoniya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 14 Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level)Leeoniya User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 7 h 15 m 57 sec
Reputation Power: 0
[Update] pretty significant rewrite (OOP/PSR-0). better extensibility, dumping of uniform arrays of objects or assoc arrays as record tables.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > A var_dump() & print_r() alternative

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap