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:
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
Previous Comments:
------------------------------------------------------------------------
[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?
------------------------------------------------------------------------
[2019-10-18 18:15:30] 6562680 at gmail dot com
any type including closed resources, nans, true/false, object of any class and so on. it can be
stringable or not. if stringable - we prefer toString
------------------------------------------------------------------------
[2019-10-18 18:13:54] 6562680 at gmail dot com
(Any type) -> short one-line (string)
------------------------------------------------------------------------
[2019-10-18 17:38:12] requinix@php.net
I'll try this another way:
What is an example of the input you will give this function, and what output do you want to get?
------------------------------------------------------------------------
[2019-10-18 17:33:42] 6562680 at gmail dot com
print_r - has linebreaks that will be replaced to '\n' string representation, has
recursions and 2000 symbols of possible length
var_dump - same
var_export - same, use it for sync both file and config
gettype - you see 'object'. nice one. all becomes explained when you see
'object'
get_class - yes, write that damn 7-lines if/else in each exception
json_encode - could be used, because does not contain line breaks, but works as complete example
creating expectation that value could be copied. No, exception should give you short info instead of
copied object
serialize - unreadable useless thing, could be improved in caches, but not for output.
just stop deny all request you see.
------------------------------------------------------------------------
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