php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63980 object members get trimmed by zero bytes
Submitted: 2013-01-13 02:33 UTC Modified: 2013-01-15 15:04 UTC
From: thbley at gmail dot com Assigned: laruence (profile)
Status: Closed Package: *General Issues
PHP Version: 5.5.0alpha3-nts OS: Win64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: thbley at gmail dot com
New email:
PHP Version: OS:

 

 [2013-01-13 02:33 UTC] 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
)

Patches

bug63980.patch (last revision 2013-01-14 03:44 UTC by laruence@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-13 12:55 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-01-13 12:55 UTC] laruence@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 16:07 UTC] thbley at gmail dot com
-Status: Feedback +Status: Open -PHP Version: 5.5.0alpha2 +PHP Version: 5.5.0alpha3-nts
 [2013-01-13 16:07 UTC] 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-14 03:44 UTC] laruence@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-14 08:23 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2013-01-14 08:23 UTC] laruence@php.net
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)
 [2013-01-14 08:24 UTC] laruence@php.net
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)
 [2013-01-14 08:32 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2013-01-14 08:32 UTC] laruence@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2013-01-15 15:04 UTC] thbley at gmail dot com
Windows snapshots are currently not available, so I tried php5.5-201301151230 on Ubuntu and it works, thanks a lot!
 [2013-11-17 09:31 UTC] laruence@php.net
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)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC