Edit report at https://bugs.php.net/bug.php?id=63980&edit=1

 ID:                 63980
 Updated by:         larue...@php.net
 Reported by:        thbley at gmail dot com
 Summary:            object members get trimmed by zero bytes
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            *General Issues
 Operating System:   Win64
 PHP Version:        5.5.0alpha3-nts
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of laruence
Revision: 
http://git.php.net/?p=php-src.git;a=commit;h=62059c16ee2f2802caa00f2aad2fa44c867dd1f1
Log: Fixed bug #63980 (object members get trimmed by zero bytes)


Previous Comments:
------------------------------------------------------------------------
[2013-01-14 03:44:57] larue...@php.net

The following patch has been added/updated:

Patch Name: bug63980.patch
Revision:   1358135097
URL:        
https://bugs.php.net/patch-display.php?bug=63980&patch=bug63980.patch&revision=1358135097

------------------------------------------------------------------------
[2013-01-13 16:07:18] thbley at gmail dot com

Thanks, var_dump() works. But it would be great if get_object_vars() and 
foreach() could be fixed.

Here is a more detailed test:

$arr = ["abc\0def" => "abc\0def"];
$obj = (object)$arr;

print_r($arr); // ok
echo "\n";
var_dump($obj); // ok
echo "\n";
echo serialize($obj); // ok
echo "\n";
echo (int)property_exists($obj, "abc"); // ok
echo "\n";
echo (int)isset($obj->{"abc"}); // ok
echo "\n";
echo json_encode($obj); // ok
echo "\n";
var_dump((array)$obj); // ok
echo "\n";

var_export($obj); // bug
echo "\n";
print_r($obj); // bug
echo "\n";
debug_zval_dump($obj); // bug
echo "\n";
var_dump(get_object_vars($obj)); // bug
echo "\n";
echo get_object_vars($obj)["abc"]; // bug
echo "\n";
foreach ($obj as $key=>$val) {
  echo $key." : ".$val."\n"; // bug
}

------------------------------------------------------------------------
[2013-01-13 12:55:01] larue...@php.net

it's due to print_r specific behavior for object's properties... 

if you use var_dump instead, you will see it's not trimmed.

------------------------------------------------------------------------
[2013-01-13 02:33:33] thbley at gmail dot com

Description:
------------
Array keys are not trimmed by zero bytes. (ok)
Object member names are trimmed by zero bytes. (bug)


Test script:
---------------
$arr = ["abc\0def" => "abc\0def"];
print_r($arr);
print_r((object)$arr);

Expected result:
----------------
Array
(
    [abc def] => abc def
)
stdClass Object
(
    [abc def] => abc def
)

Actual result:
--------------
Array
(
    [abc def] => abc def
)
stdClass Object
(
    [abc] => abc def
)


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



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63980&edit=1

Reply via email to