php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45648 Visibility of private in another Obj of that same class
Submitted: 2008-07-28 18:21 UTC Modified: 2008-07-28 21:15 UTC
From: gwd at heex dot pl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.6 OS: Win XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gwd at heex dot pl
New email:
PHP Version: OS:

 

 [2008-07-28 18:21 UTC] gwd at heex dot pl
Description:
------------
Private/protected property/method is visible in methods of another object of that same class

Reproduce code:
---------------
class A {
      private $sameVar = "it's private variable!<br>";
      
      private function testMthd () {
            echo "it's private method!<br>";
      }
      
      public function testVar($otherObj) {
            echo $otherObj->sameVar;
            $otherObj->testMthd();
      }
}

$sm1 = new A();
$sm2 = new A();

$sm1->testVar($sm2);

Expected result:
----------------
it should rise an "Fatal error: Cannot access private property"

Actual result:
--------------
it's private variable!
it's private method!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-28 18:52 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Visibility is bound to the class, not the object.
 [2008-07-28 21:15 UTC] gwd at heex dot pl
Sorry, my fault. I should know it.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 09:01:27 2025 UTC