php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69568 call a private function in closure failed
Submitted: 2015-05-04 06:05 UTC Modified: 2015-05-06 13:46 UTC
From: guoxiao08 at gmail dot com Assigned: levim (profile)
Status: Closed Package: *General Issues
PHP Version: 5.5.24 OS: Not related
Private report: No CVE-ID: None
 [2015-05-04 06:05 UTC] guoxiao08 at gmail dot com
Description:
------------
Call a private static function in a subclass, and it failed in 5.5.
However it runs normally in php 5.4

Test script:
---------------
<?php
class A {

    private static function testprivate() {
        return 1;
    }
    public static function test() {
        return function() {
            return self::testprivate();
        };
    }
}

class B extends A {
}

$fn = B::test();
echo $fn();

Expected result:
----------------
1

Actual result:
--------------
Fatal error: Call to private method A::testprivate() from context 'B' in /tmp/test.php on line 9

Call Stack:
    0.0048     645824   1. {main}() /tmp/test.php:0
    0.0048     646304   2. B::{closure:/tmp/test.php:8-10}() /tmp/test.php:18

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-04 11:04 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-05-04 11:04 UTC] cmb@php.net
The behavior changed with PHP 5.4.30 and PHP 5.5.14: <http://3v4l.org/WSIu7>. It's most likely related to the fix for bug #66622.
 [2015-05-04 11:18 UTC] laruence@php.net
-Assigned To: +Assigned To: levim
 [2015-05-04 11:18 UTC] laruence@php.net
@levim please check this . thanks
 [2015-05-04 11:32 UTC] laruence@php.net
I think this is conflicts with:

<?php

class A {
    static function foo() {
        $f = function() {
            return static::class;
        };
        return $f();
    }
}

class B extends A {}

var_dump(B::foo());

?>

:<
 [2015-05-06 13:42 UTC] laruence@php.net
this has been fixed in master by nikic , anyway, due to ABI change, I don't think the change can be merged downward to 5.6/5.5
 [2015-05-06 13:46 UTC] levim@php.net
-Status: Verified +Status: Closed
 [2015-05-06 13:46 UTC] levim@php.net
Yeah we were discussing and working on this yesterday. We believe this should be fixed without other regressions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC