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

From: Date: Fri, 18 Oct 2019 18:50:30 +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-223274@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
 Updated by:         requinix@php.net
 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:

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?


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2019-10-18 17:28:50] 6562680 at gmail dot com

I mark this "bug" as feature/change request, are you saw it?

Have you tried to print exception with var_export? Did you see these "\n" in every debug
panel that try to replace line breaks? Why did you ask me to do that? Please, review that comment if
you regard community experience

------------------------------------------------------------------------


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


Thread (16 messages)

« previous php.bugs (#223274) next »