Bug #73862 [Opn]: Accessing protected property and method of sibling class is inconsistent
| From: | after89 at gmail dot com | Date: | Wed, 04 Jan 2017 19:07:22 +0000 |
| Subject: | Bug #73862 [Opn]: Accessing protected property and method of sibling class is inconsistent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206304@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73862&edit=1
ID: 73862
User updated by: after89 at gmail dot com
Reported by: after89 at gmail dot com
Summary: Accessing protected property and method of sibling
class is inconsistent
Status: Open
Type: Bug
Package: *General Issues
PHP Version: 7.1.0
Block user comment: N
Private report: N
New Comment:
Valid code for method:
<?php
class Base { protected function foo() {} }
class Other extends Base { protected function foo() { echo "OK"; } }
class Child extends Base { public function bar() { $otherBase = new Other(); $otherBase->foo();
} }
$child = new Child();
$child->bar();
Previous Comments:
------------------------------------------------------------------------
[2017-01-04 19:05:55] after89 at gmail dot com
Description:
------------
Accessing protected property defined in superclass of current context on object that is sibling of
current context class (extends one of the base class) is not possible (https://3v4l.org/BODds).
Althrough accessing method in the same manner is valid (https://3v4l.org/8DNBa).
Both of this behaviours should be consistent.
Test script:
---------------
<?php
class Base { protected $foo = 'Base'; }
class Other extends Base { protected $foo = 'Other'; }
class Child extends Base { public function bar() { $otherBase = new Other(); echo
$otherBase->foo; } }
$child = new Child();
$child->bar();
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73862&edit=1