note 45403 deleted from language.oop by danbrown

From: Date: Sat, 07 Nov 2009 19:03:44 +0000
Subject: note 45403 deleted from language.oop by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162567@lists.php.net to get a copy of this message
Note Submitter: email at richardlee dot info ---- An example of how to pass an object back into its own class for direct use. (thisClass.php) <?php class thisClass{ var $var1; function thisClass($value) {$this->var1 = $value;} function set_var1($value) {$this->var1 = $value;} function get_var1() {return $this->var1;} function showVar() {echo "<p>var1 = ".$this->var1."</p>";} function callShowVar($object) {$object->showVar();} function copyObject($object) {$this->var1 = $object->get_var1();} } ?> (test.php) <?php require_once('class.php'); $thisObject = new thisClass(3); $thatObject = new thisClass(1); $thatObject->callShowVar($thisObject); //outputs "var1 = 3" $thisObject->showVar(); //outputs "var1 = 3" $thatObject->showVar(); //outputs "var1 = 1" $thatObject->copyObject($thisObject); $thatObject->showVar(); //outputs "var1 = 3" ?>

« previous php.notes (#162567) next »