Req #73811 [Com]: Add var_dump-like function to return output as string

From: Date: Sun, 25 Dec 2016 21:38:21 +0000
Subject: Req #73811 [Com]: Add var_dump-like function to return output as string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206203@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73811&edit=1 ID: 73811 Comment by: pjvleeuwen at gmail dot com Reported by: pjvleeuwen at gmail dot com Summary: Add var_dump-like function to return output as string Status: Open Type: Feature/Change Request Package: Variables related Operating System: n/a PHP Version: 7.1.0 Block user comment: N Private report: N New Comment: You are right, an oversight. Thanks. A new function (I would find the var_dump_r suggestion the most consistent) would indeed be a possibility. But it seems that adding yet another function might not be very scaleable, these three already feel quite ad hoc invented, while they are quite similar: represent some variable as text. I would propose to add a 3rd $format argument (optional) to var_export (which I think has to most concise name): PRINTR_PARSABLE - default option, current output format of var_export PRINTR_HUMAN - current output format of print_r PRINTR_TYPED - current output format of var_dump The main benefit with only these 3 constants would be allowing var_dump output format to be returned as string in a consistent way. print_r would become redundant. This would allow other formats to be added without a further need to be creative with similar sounding function names. Previous Comments: ------------------------------------------------------------------------ [2016-12-25 14:28:55] requinix@php.net Adding $return would not work: how would var_dump() know that you aren't trying to dump a bool(true) but passing a special argument? This would have to be a new function, eg. var_dump_r or var_rdump. ------------------------------------------------------------------------ [2016-12-25 14:09:48] pjvleeuwen at gmail dot com Description: ------------ Please allow var_dump to return the output as a string instead of printing. Basically adding the same $return parameter and behavior as for var_export and print_r. Adding this parameter would be fully backwards compatible. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73811&edit=1

« previous php.bugs (#206203) next »