note 45403 added to language.oop

From: Date: Sun, 05 Sep 2004 17:11:00 +0000
Subject: note 45403 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-76074@lists.php.net to get a copy of this message
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" ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45403 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45403&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45403&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76074) next »