note 61686 added to language.oop

From: Date: Thu, 09 Feb 2006 14:57:11 +0000
Subject: note 61686 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-103364@lists.php.net to get a copy of this message
PHP Allow to extend a class in a dinamic way into a object and only affects that object not the others of the same class. I was developing a persistence class and i found this: <?php class MyClass { var $Prop1; // Into the constructor i create a propertie that was not declared before. function MyClass() { $this->Prop2 = "This was not declared but now exists into the object"; } function setProp($PropName, $PropValue) { $this->$PropName = $PropValue; } } $MyObj = new MyClass(); $MyObj->setProp("Prop1", "This was declared and now has value"); $MyObj->setProp("Prop3", "This was declared by setProp() method."); $MyObj->Prop4 = "This was declared out of the class definition"; echo "Prop1: ".$MyObj->Prop1." <br />\r\n"; echo "Prop2: ".$MyObj->Prop2." <br />\r\n"; echo "Prop3: ".$MyObj->Prop3." <br />\r\n"; echo "Prop4: ".$MyObj->Prop4." <br />\r\n"; ?> This could be very useful, but very dangerous too, take care. ---- Server IP: 64.246.30.37 Probable Submitter: 24.232.219.88 ---- Manual Page -- http://www.php.net/manual/en/language.oop.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61686 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61686&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61686&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61686&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61686&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61686&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61686&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61686&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61686&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103364) next »