Req #78064 [Opn->Fbk]: var_dump() should display the invisible characters code

From: Date: Mon, 27 May 2019 11:17:15 +0000
Subject: Req #78064 [Opn->Fbk]: var_dump() should display the invisible characters code
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221009@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78064&edit=1 ID: 78064 Updated by: sjon@php.net Reported by: jerome at deuchnord dot fr Summary: var_dump() should display the invisible characters code -Status: Open +Status: Feedback Type: Feature/Change Request Package: *General Issues Operating System: Arch Linux PHP Version: 7.3.5 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2019-05-25 10:20:51] sjon@php.net While an interesting request - you have some incorrect assumptions. First of all - var_dump actually shows you the difference in the number of characters as illustrated by the included string-length. (it will be string(12) without the BOM). Additionally - var_dump actually outputs these characters just fine - it's probably your browser that decides not to show them. This can be verified by passing the output through xxd (or an editor that displays it). For example, when encoding the output from var_dump as json: $ curl -HAccept:application/json https://3v4l.org/rjuMl will show you "output": [{"versions":"7.1.25 - 7.3.5","output":"string(12) \"Hello World!\"\n---------------\nstring(15) \"\ufeffHello World!\"\n"}] With encoding set to HTML it's also visible: $ curl https://3v4l.org/rjuMl|xxd will show you: 00000fd0: 2d2d 2d2d 2d2d 2d2d 2d0a 7374 7269 6e67 ---------.string 00000fe0: 2831 3529 2022 efbb bf48 656c 6c6f 2057 (15) "...Hello W 00000ff0: 6f72 6c64 2122 0a3c 2f64 643e 3c2f 646c orld!".</dd></dl ------------------------------------------------------------------------ [2019-05-24 11:12:13] jerome at deuchnord dot fr Description: ------------ In some circumstances, we may get invisible characters in a variable. Currently, these characters are not visible with var_dump() - the only way you can figure out their presence is by copying it and paste it on an editor that displays it (for instance Vim). This behavior leads to strong difficulties for the developers to debug their script. This becomes really a problem for instance when your variable is an array and there is an invisible character in one key. Test script: --------------- $bom = chr(0xef) . chr(0xbb) . chr(0xbf); $str = $bom.'Hello World!'; var_dump($str); // string(15) "Hello World!" Expected result: ---------------- $bom = chr(0xef) . chr(0xbb) . chr(0xbf); $str = $bom.'Hello World!'; var_dump($str); // string(15) "\0xef\0xbb\0xfeHello World!" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78064&edit=1

« previous php.bugs (#221009) next »