Bug #69766 [Ver->Dup]: protected property can be accessed from another class that has the same parent

From: Date: Sun, 27 Mar 2016 16:16:02 +0000
Subject: Bug #69766 [Ver->Dup]: protected property can be accessed from another class that has the same parent
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200163@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69766&edit=1 ID: 69766 Updated by: nikic@php.net Reported by: tornike dot comaia dot mail at gmail dot com Summary: protected property can be accessed from another class that has the same parent -Status: Verified +Status: Duplicate Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: 5.6.9 Block user comment: N Private report: N New Comment: Duplicate of bug #50892. Previous Comments: ------------------------------------------------------------------------ [2015-06-10 00:34:14] cmb@php.net Verified: <http://3v4l.org/jhq6h>. Apparently, the behavior has changed as of PHP 5.2.0. ------------------------------------------------------------------------ [2015-06-06 17:29:59] tornike dot comaia dot mail at gmail dot com It is possible to access the protected property of class A within the class B if both classes have the same parent - C, that defines the property, but it is possible unless the property is overriden in child class A or B ------------------------------------------------------------------------ [2015-06-06 17:26:47] tornike dot comaia dot mail at gmail dot com Description: ------------ It is possible to access the protected property of class A within the class B if both classes have the same parent - C, that defined the property unless the property is overriden in child class A or B Test script: --------------- <?php class C { protected $data; } class A extends C { } class B extends C { public function test() { $obj = new A(); $obj->data = 'Hello world'; echo $obj->data; } } ?> Expected result: ---------------- Unless the class B is not the child of the class A, an error must be risen when trying to access the protected property of the class A within class B ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69766&edit=1

« previous php.bugs (#200163) next »