#39532 [Opn->Bgs]: Error in acess a private attribute in a extended method
| From: | tony2001@php.net | Date: | Thu, 16 Nov 2006 13:12:08 +0000 |
| Subject: | #39532 [Opn->Bgs]: Error in acess a private attribute in a extended method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-105084@lists.php.net to get a copy of this message | ||
ID: 39532
Updated by: tony2001@php.net
Reported By: thiago dot henrique dot mata at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Windows Xp Professional
PHP Version: 5.2.0
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2006-11-16 13:04:06] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39532&edit=1