note 61686 deleted from language.oop by danbrown

From: Date: Sat, 07 Nov 2009 19:03:05 +0000
Subject: note 61686 deleted from language.oop by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162556@lists.php.net to get a copy of this message
Note Submitter: Leonel Quinteros ---- 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.

« previous php.notes (#162556) next »