php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69537 __debugInfo with empty string for key gives error
Submitted: 2015-04-27 17:02 UTC Modified: 2015-05-08 22:13 UTC
From: danack@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.8 OS: N/A
Private report: No CVE-ID: None
 [2015-04-27 17:02 UTC] danack@php.net
Description:
------------
Returning debug info through the function __debugInfo with an empty key as the key for the first element gives a warning message "Notice: Illegal member variable name in /in/0raS3 on line 10"

Test script:
---------------
<?php

class A{
    function __debugInfo(){
        return ['' => 1];
    }
}


print_r(new A);

Expected result:
----------------
A Object
(
    [] => 1
)

Actual result:
--------------
A Object
(
    [
Notice: Illegal member variable name in /in/0raS3 on line 10
] => 1
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-28 02:42 UTC] laruence@php.net
I have to say it's expected behavior

see: https://github.com/laruence/php-src/blob/master/Zend/tests/debug_info.phpt
 [2015-04-28 02:42 UTC] laruence@php.net
or at least a expected side affect
 [2015-04-28 02:43 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2015-04-28 12:35 UTC] danack@php.net
Hi Laruence,

Sorry, I don't understand what you mean. The tests don't cover the case when the key is empty.

The issue also doesn't manifest when the empty key isn't the first element i.e. this:

<?php 

class A{
    function __debugInfo(){
        return [
            
            "foo" => 'bar',
            '' => 'bar',
        ];
    }
}


print_r(new A);

?>

works fine.
 [2015-04-28 12:43 UTC] danack@php.net
-Status: Feedback +Status: Open
 [2015-04-29 05:21 UTC] laruence@php.net
$ sapi/cli/php -n -d error_reporting=-1 /tmp/1.php
A Object
(
    [foo] => bar
    [
Notice: Illegal member variable name in /tmp/1.php on line 14
] => bar
)
 [2015-04-29 05:22 UTC] laruence@php.net
the problem is, we use \0class_name\0property_name for private properties.

so, \0 has a special meaning if it's the lead char.
 [2015-05-05 03:09 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2015-05-05 03:09 UTC] laruence@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


 [2015-05-08 22:13 UTC] ircmaxell@php.net
Reading the \0 is a bug, as that's past the end of the string (well, greater than the length variable).

The bug isn't saying that strings starting with \0 should be accepted. It's saying that it shouldn't even get that far.

Basically, the check at http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_compile.c#1242 should also include a check against name->len:

    if (name->len == 0 || name->val[0] != '\0') {
 [2015-05-08 22:13 UTC] ircmaxell@php.net
-Status: Not a bug +Status: Verified
 [2016-04-03 11:40 UTC] krakjoe@php.net
Automatic comment on behalf of krakjoe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=14e4c610e95a69b464596640e1f3996687e3d5ca
Log: Fix #69537: __debugInfo with empty string for key gives error
 [2016-04-03 11:40 UTC] krakjoe@php.net
-Status: Verified +Status: Closed
 [2016-04-03 11:41 UTC] krakjoe@php.net
Automatic comment on behalf of krakjoe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=91c10662c887c0e0a80844b1655cf329c5c58352
Log: fix #69537: __debugInfo with empty string for key gives error
 [2016-04-03 11:41 UTC] krakjoe@php.net
Automatic comment on behalf of krakjoe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=91c10662c887c0e0a80844b1655cf329c5c58352
Log: fix #69537: __debugInfo with empty string for key gives error
 [2016-04-04 22:12 UTC] mbeccati@php.net
Automatic comment on behalf of krakjoe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=14e4c610e95a69b464596640e1f3996687e3d5ca
Log: Fix #69537: __debugInfo with empty string for key gives error
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of krakjoe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=91c10662c887c0e0a80844b1655cf329c5c58352
Log: fix #69537: __debugInfo with empty string for key gives error
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC