php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77613 method visibility change
Submitted: 2019-02-13 12:31 UTC Modified: 2019-02-13 13:32 UTC
From: gstachniuk at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: Next Minor Version OS: Ubuntu 18.04.1 LTS
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: gstachniuk at gmail dot com
New email:
PHP Version: OS:

 

 [2019-02-13 12:31 UTC] gstachniuk at gmail dot com
Description:
------------
in php version 7.4 I can not change methods visibility anymore.

Test script:
---------------
class CustomException extends \RuntimeException {
  private function __construct(string $msg) {
    return new self($msg);
  }
}

Expected result:
----------------
no error message 
```
::__construct() must be public (as in class Exception) in
```


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-13 12:50 UTC] nikic@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem -Assigned To: +Assigned To: nikic
 [2019-02-13 13:23 UTC] nikic@php.net
Here is another reproducer:

class A {
    public function __construct() {
        static $foo;
    }
}

class B extends A { }

class C extends B {
    private function __construct() {}
}

The important bit is that
a) we have an intermediate class that inherits the ctor
b) the ctor is duplicated. In the original example this is due to an internal class, in this example due to use of static variables.

The reason why this issue occurs is that "parent->common.scope->constructor == parent" is used to detect a constructor. However, if parent comes from class B then parent->common.scope will be A, which has a different instance of the same constructor.
 [2019-02-13 13:32 UTC] nikic@php.net
-Assigned To: nikic +Assigned To: dmitry
 [2019-02-13 13:32 UTC] nikic@php.net
@dmitry: Can you please take a look at this?

This is easy enough to fix by checking constructor on the actual parent CE rather than common.scope, but I'm wondering if we shouldn't bring back ZEND_ACC_CTOR. The premise was that it can be replaced by a fe->common.scope->constructor == fe check, but this is not the case.
 [2019-02-14 10:18 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=43a7d95016761787cace63fb52e93e27e123d0cc
Log: Fixed bug #77613 (method visibility change) (reverted ZEND_ACC_CTOR and ZEND_ACC_DTOR flags removal)
 [2019-02-14 10:18 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC