php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74340 Magic function __get has different behavior in php 7.1.x
Submitted: 2017-03-30 13:51 UTC Modified: 2017-04-02 11:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: x dot xiang at outlook dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 7.1.3 OS: macOS/Linux
Private report: No CVE-ID:
 [2017-03-30 13:51 UTC] x dot xiang at outlook dot com
Description:
------------
Does the recursive call to the magic method be allowed?

Actual result in php 5.x and 7.0.x:
__get test
PHP Notice:  Undefined property: Test::$test in /data1/data/playcrab/tmp/test4.php on line 10
__get test2
PHP Notice:  Undefined property: Test::$test in /data1/data/playcrab/tmp/test4.php on line 12

Actual result in php 7.1.x:
__get test
PHP Notice:  Undefined property: Test::$test in /data1/data/playcrab/tmp/test4.php on line 10
__get test2
__get test

Test script:
---------------
<?php
class Test
{
    public function __get($var)
    {
        static $first = true;
        echo '__get '.$var.PHP_EOL;
        if ($first) {
            $first = false;
            $this->$var;
            $this->{$var.'2'};
            $this->$var;
        }
    }
}

$test = new Test;
$test->test;


Expected result:
----------------
__get test
__get test
__get test2
__get test

Actual result:
--------------
__get test
PHP Notice:  Undefined property: Test::$test in /data1/data/playcrab/tmp/test4.php on line 10
__get test2
__get test

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-02 11:29 UTC] nikic@php.net
-Summary: Magic function __get have different behavior in php 7.1.x +Summary: Magic function __get has different behavior in php 7.1.x -Type: Feature/Change Request +Type: Bug
 [2017-04-02 11:31 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=fe46a7da78f037fe032f27c9b65667c675a6dd8d
Log: Fixed bug #74340
 [2017-04-02 11:31 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Aug 20 17:01:35 2017 UTC