php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69766 protected property can be accessed from another class that has the same parent
Submitted: 2015-06-06 17:26 UTC Modified: 2016-03-27 16:16 UTC
Votes:15
Avg. Score:4.7 ± 1.0
Reproduced:15 of 15 (100.0%)
Same Version:4 (26.7%)
Same OS:4 (26.7%)
From: tornike dot comaia dot mail at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.6.9 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tornike dot comaia dot mail at gmail dot com
New email:
PHP Version: OS:

 

 [2015-06-06 17:26 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-06 17:29 UTC] 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-10 00:34 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-06-10 00:34 UTC] cmb@php.net
Verified: <http://3v4l.org/jhq6h>. Apparently, the behavior has changed as of PHP 5.2.0.
 [2015-06-10 00:34 UTC] cmb@php.net
-Summary: protected property can be accesed from another class that has the same parent +Summary: protected property can be accessed from another class that has the same parent -PHP Version: 5.5.26RC1 +PHP Version: 5.6.9
 [2016-03-27 16:16 UTC] nikic@php.net
-Status: Verified +Status: Duplicate
 [2016-03-27 16:16 UTC] nikic@php.net
Duplicate of bug #50892.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC