php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22489 Private members are available to derived classes
Submitted: 2003-03-01 10:36 UTC Modified: 2003-03-02 09:58 UTC
From: marcot at tabini dot ca Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2003-03-01 (dev) OS: Shouldn't matter
Private report: No CVE-ID: None
 [2003-03-01 10:36 UTC] marcot at tabini dot ca
Configure:

./configure \
--with-apxs=/usr/local/apache/bin/apxs

For example:

<?

class a
{
  private $c;

  function __construct()
  {
    $this->c = "a::c";
  }
}

class b
  extends a
{
  private $d;

  function _construct()
  {
    $this->d = 'b::d';
  }

  function test()
  {
    echo $this->c;
  }
}

$b = new b;

//echo $b->d;
$b->test();

?>

If executed, The first echo statement returns an error, as expected. The $b->test() call, however, returns `a::c', which I think is incorrect, as it should either not return anything or produce an error, since a::$c is declared as private and should not be available to the b namespace.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-01 10:46 UTC] helly@php.net
NO! & YES there is an error.

No: You are declaring a *new* dynamic property c in b
which hides c from a.

YES: there is a memory leak:
/usr/src/php4-HEAD/Zend/zend_language_scanner.l(1084) :  Freeing 0x40998D38 (7 bytes), script=/usr/src/php4-HEAD/tests/classes/private_members.php

I'll have a look into it
 [2003-03-01 10:50 UTC] marcot at tabini dot ca
Okay, but even so I'm not assigning it the value `a::c'. So, even if I'm creating a new property that hides the previous one, it should not have any contents, no?
 [2003-03-02 08:26 UTC] helly@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

Your class b doesn't have a constructor (only one underscore). Therefor a::__construct is used as a constructor and that is why b->test() shows a value.

The leak is already fixed and the rest is no bug.
 [2003-03-02 09:58 UTC] marcot at tabini dot ca
Thanks for taking the time to review the bug. You're certainly right--my b class doesn't have a constructor, and therefore the engine defaults to a:__construct().

Unfortunately, I still don't think that it's behaving correctly. a:__construct() should reside in the context of a, and therefore it should access a::$c, not create a new dynamic property b::$c. If this is the way the engine works, then a parent class has access to its subclasses contexts, which I don't think is right.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jan 11 15:00:02 2026 UTC