php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26299 Inheritance problem: an object can have two same-named private variables
Submitted: 2003-11-18 10:05 UTC Modified: 2003-11-18 10:29 UTC
From: forseti at oak dot rpg dot pl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0b2 (beta2) OS: Windows 98 SE
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: forseti at oak dot rpg dot pl
New email:
PHP Version: OS:

 

 [2003-11-18 10:05 UTC] forseti at oak dot rpg dot pl
Description:
------------
When extending a class, private member variables from parent class are retained even if child class defines same-named variable. 

Reproduce code:
---------------
<?php 
class A {
	private $a = 'From class A';
} 

class B extends A{
	private $a = 'From class B';
}
echo '<pre>';print_r(new B);echo '</pre>';
?>

Expected result:
----------------
b Object
(
    [a:private] => From class B
)



Actual result:
--------------
b Object
(
    [a:private] => From class B
    [a:private] => From class A
)



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-18 10:29 UTC] jay@php.net
This is expected. When a member is private, it can only be 
seen by the class it is a member of. Class B has no idea 
class A also has a member called $a and goes ahead and 
creates one. It's just a matter of visibility. 
 
J 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 07:01:33 2025 UTC