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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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