php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39532 Error in acess a private attribute in a extended method
Submitted: 2006-11-16 13:04 UTC Modified: 2006-11-16 13:12 UTC
From: thiago dot henrique dot mata at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.0 OS: Windows Xp Professional
Private report: No CVE-ID: None
 [2006-11-16 13:04 UTC] thiago dot henrique dot mata at gmail dot com
Description:
------------
A extend method cannot acess a private attribute but if this be rewrite it's does.

Reproduce code:
---------------
<?php
class parentClass{
	public function setMyPrivateValues( $arrData ){
		foreach( $arrData as $strKey => $mixValue ){ $this->$strKey = $mixValue; }
	}
}
class childClass extends parentClass{
	private $strName;
}
class childClass2 extends childClass{
	public function setMyPrivateValues( $arrData ){
		foreach( $arrData as $strKey => $mixValue ){ $this->$strKey = $mixValue; }
	}
}
$arrData = array( 'strName' => 'jonh' );
$objChild2 = new childClass2();	// If i rewrite the method
$objChild2->setMyPrivateValues( $arrData ); // Set a private attribute
$objChild = new childClass(); // If i dont rewrite the method
$objChild->setMyPrivateValues( $arrData ); // Set a private attribute
?>

Expected result:
----------------
both class changed.

Actual result:
--------------
Fatal error: Cannot access private property childClass::$strName in nameFile.php on line 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-16 13:12 UTC] tony2001@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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 15:01:29 2024 UTC