Skip to content

Fix GH-19406: Redeclaring a protected constant in a child class should work #19415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: PHP-8.4
Choose a base branch
from

Conversation

alexandre-daubois
Copy link
Member

Fix #19406

The PR only focuses on constants, the other failing cases seem to be fixed already. I targeted 8.4 because of what's been mentioned in the issue.

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right solution. It allows accessing protected constants on any "cousin" class. E.g.

class P {}

class C1 extends P {
    protected const C = 'C1';
}

class C2 extends P {
    public static function test() {
        var_dump(C1::C);
    }
}

C2::test();
// string(2) "C1"

The same does not apply to properties. Time complexity is also not great, as zend_check_protected() itself has two loops, giving us O(n²).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants