Req #78683 [Nab]: [ Feature ] Add function to safely print nested objects / arrays in Exceptions

From: Date: Sat, 19 Oct 2019 07:28:38 +0000
Subject: Req #78683 [Nab]: [ Feature ] Add function to safely print nested objects / arrays in Exceptions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223284@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78683&edit=1 ID: 78683 User updated by: 6562680 at gmail dot com Reported by: 6562680 at gmail dot com Summary: [ Feature ] Add function to safely print nested objects / arrays in Exceptions Status: Not a bug Type: Feature/Change Request Package: *General Issues Operating System: Win10 PHP Version: 7.3.10 Block user comment: N Private report: N New Comment: understand all about php. array_map(func, array) but array_filter(array, func) i can put here 12 bugs that makes me angry from but instead of make it better, we talking talking talking. creating rfc, explaining and deny features by any reason i tried 6 times (there is 1 time) - nothing changed. i understand the logic of community speech php is dead its not dead, its freezed. Previous Comments: ------------------------------------------------------------------------ [2019-10-19 02:24:20] requinix@php.net Here's the thing. Adding a new function to the core because someone doesn't like the 8 (I forgot debug_zval_dump) or more functions that serve a similar purpose isn't enough of a reason to do so. The whole point of allowing people to write their own classes and functions is specifically because PHP won't have everything already, and sharing that custom code between projects is why PEAR and Composer exist. So here's my offer. Go on the internals mailing list and see what they think - I'm not saying this needs an RFC, just to talk about it - and if they agree with you that another function is warranted then so be it. ------------------------------------------------------------------------ [2019-10-19 00:37:57] 6562680 at gmail dot com oh my bad i wrote topic name "safely print" i mean safely for interpreter you know, when you calling "is_nan" (that returns bool) you could get fatal error like "you variable is not a float", i mean "safely for that stuff" (strval) object -> fatal "non-stringable" i mean without this fatals everywhere that could be solved only with if/else ------------------------------------------------------------------------ [2019-10-19 00:22:45] 6562680 at gmail dot com String could be { String(27) "My\0BadString\27With\t\nTabs...." } // split vars with 1 space logval(...$arguments) // cut every output to maxlen then wrap with '{ <Type> [#<id>] <Cutstr> } printval(int $maxlen, ...$arguments); ------------------------------------------------------------------------ [2019-10-19 00:18:22] 6562680 at gmail dot com Its not a serialization. To serialize we still should pass additional argument. Its not for logging where you should get full explained output. The function is used only at info level, between the developers, in maybe notifications / exception. I dont cry that is REQUIRED AS AIR. Will be great to have this one to print "variable info" in short as we can, to help developer to explain while debugging without analyze logs. No more! It just like "console.log()" keeping in the mind that we havent interactive dropdown lists, and have only one string How would it produce a "short one-line string" for something like $_SERVER? { Array(27) } What does it produce for classes without a __toString? { Object #27 My\Awesome\Namespace } What about binary strings? Not sure: represent as is, but maybe "\0PropertyName\0 representation Control characters like newlines and tabs? "Still '\t' and '\n'. If it is a string with these chars - ok, you pass it you get it. Var_dump() creates it to format output. And how *is* recursion supposed to be handled? In this function - noway and not requested. You just display object id and classname, it will be used like this: throw new \UnexpectedValueException('Incorrect object passed: FUNC($var) => FUNC(...$allowed_list) (split with space if unpack) Could it be that maybe your logging method of sticking something into the exception message isn't good enough? And that maybe you need a more complex solution, like PSR-3? Again i know about logging. know about extending exceptions and can send my exceptions to bugtracker. I just want to skip requirement to deep debugging and log analyzing on easy validation stuff like "value not in list". When i debugging - i still remember what values i expect, i just need to short hint what value was passed (and resulted with exception). I dont need exactly deep representation and ability to copy and convert back. Just view short hint about like if you use Symfony\VarDumper but without dropdowns - only type/id/length ------------------------------------------------------------------------ [2019-10-18 18:50:30] requinix@php.net How would it produce a "short one-line string" for something like $_SERVER? What does it produce for classes without a __toString? What about binary strings? Control characters like newlines and tabs? And how *is* recursion supposed to be handled? Could it be that maybe your logging method of sticking something into the exception message isn't good enough? And that maybe you need a more complex solution, like PSR-3? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=78683 -- Edit this bug report at https://bugs.php.net/bug.php?id=78683&edit=1

« previous php.bugs (#223284) next »