php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61773 each() are printing null characters for objects
Submitted: 2012-04-19 13:05 UTC Modified: 2012-04-19 20:22 UTC
From: dread dot eklund at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dread dot eklund at gmail dot com
New email:
PHP Version: OS:

 

 [2012-04-19 13:05 UTC] dread dot eklund at gmail dot com
Description:
------------
When using the each() function on objects, private and protected variables gets a NUL character around them (see expected result).

Create the test script and view it in a browser (I used Firefox 11.0). 

If you send an email with the output, the mail() function will just truncate the message after the NUL character

Test script:
---------------
class Foo
{
   public $a;
   protected $b;
   private $c;

   function bar($value) {
      echo $value;
   }
}

$tmp = new Foo();

while(list($key, $value) = each($tmp)) {
   var_dump($key);
}

Expected result:
----------------
string(1) "a"
string(4) "*b"
string(6) "Fooc"

Without the NUL character

Actual result:
--------------
string(1) "a"
string(4) "�*�b"
string(6) "�Foo�c"

� = NUL character, ASCII code (dec): 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-19 20:22 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

using each() on objects is a legacy feature, the NULL-bytes are part of the internal representation of private and protected elements.
 [2012-04-19 20:22 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 00:01:23 2020 UTC