|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-11-16 13:12 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 20:00:01 2025 UTC |
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