Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Protected properties are not scoped according to their prototype #19044

Closed
@bwoebi

Description

@bwoebi

Description

The following code (https://3v4l.org/7Xf05#v8.4.10):

<?phpabstractclass P {abstractprotected$foo { get; }}classC1extends P {protected$foo =1;}classC2extends P {protected$foo =2;staticfunctionfoo($c) {return$c->foo; }}var_dump(C2::foo(newC2));var_dump(C2::foo(newC1));

Resulted in this output:

int(2)Fatal error: Uncaught Error: Cannot access protected property C1::$foo in /in/7Xf05:14Stack trace:#0 /in/7Xf05(18): C2::foo(Object(C1))#1 {main}  thrown in /in/7Xf05 on line 14

But I expected this output instead:

int(2)int(1)

Doing the same with methods works flawlessly (https://3v4l.org/iQo81#v8.4.10):

<?phpabstractclass P {abstractprotectedfunctionfoo();}classC1extends P {protectedfunctionfoo() {return1; }}classC2extends P {protectedfunctionfoo() {return2; }staticfunctiondoFoo($c) {return$c->foo(); }}var_dump(C2::doFoo(newC2));var_dump(C2::doFoo(newC1));

results in the expected

int(2)int(1)

PHP Version

PHP 8.4.10

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp