php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73515 Problems with private properties of the same name in inherited classes
Submitted: 2016-11-14 13:37 UTC Modified: 2016-11-27 04:22 UTC
From: aimeos at aimeos dot org Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.6.28 OS: Linux/Ubunutu
Private report: No CVE-ID: None
 [2016-11-14 13:37 UTC] aimeos at aimeos dot org
Description:
------------
There's a problem if both, the child and parent class contains a PRIVATE array variable using the same name which initially share the same content. Methods in the child class sometimes access the content of the parent class variable even it both are private for their own class.

This doesn't always happen and might be a problem if more boundary conditions apply. Maybe it's caused by the copy on write optimization for arrays. It's very likely to affect PHP 5.5 and before as well.

Test script:
---------------
<?php

class ParentClass
{
  private $values;

  public function __construct( array $values )
  {
    $this->values = $values;
  }
}


class ChildClass extends ParentClass
{
  private $values;

  public function __construct( array $values )
  {
    parent::__construct( $values );
    $this->values = $values;
  }

  public function getTest()
  {
    if( isset( $this->values['test'] ) ) {
      return $this->values['test'];
    }
  }

  public function setTest( $value )
  {
    return $this->values['test'] = $value;
  }
}


$object = new ChildClass( array( 'test' => 0 ) );
$object->setTest( 1 );
echo 'val: ' . $object->getTest() . PHP_EOL;
print_r( $object );

Expected result:
----------------
1

Actual result:
--------------
0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-14 13:44 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2016-11-14 13:44 UTC] nikic@php.net
The provided script does not reproduce the problem: https://3v4l.org/A7eN7

Are you sure the exact code you posted exhibits this issue? If so, which extensions do you use? Does the problem persists if you use "php -n"?
 [2016-11-27 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC