note 54301 added to language.oop5

From: Date: Thu, 30 Jun 2005 01:04:33 +0000
Subject: note 54301 added to language.oop5
Groups: php.notes 
Request: Send a blank email to php-notes+get-91167@lists.php.net to get a copy of this message
<?PHP // How to hold objects in an arrayList and retrieve it // // Interface implementation // class Data { public $Name; public $Age; public $Address; public function __construct($Name,$Age,$Address) { $this->Name = $Name; $this->Age = $Age; $this->Address = $Address; } public function __destruct() { echo "Default Constructor...\n"; } } $ArrayList = array(); $ArrayList[0] = new Data("John McDonald","65","Address"); $ArrayList[1] = new Data("Turgut Z. Yesilyurt","30","NJ, USA"); $ArrayList[2] = new Data("Maria ","25","NJ, USA"); print_r($ArrayList); $obj1 = $ArrayList[1]; echo "Name : ".$obj1->Name."\n"; echo "Age : ".$obj1->Age."\n"; echo "Address : ".$obj1->Address."\n"; // Interface Usage // interface ShowMe { public function ShowName(); } class ShowData implements ShowMe { public $obj; public function __construct($Obj) { $this->obj = $Obj; $this->ShowName(); } public function ShowName() { echo "Age : ".$this->obj->Age."\n"; } } echo "\nDisplay Single Data =========================\n\n"; new ShowData($ArrayList[1]); echo "\n=============================================\n"; // Turgut Z. YESILYURT, MS // Software Developer // // NJ, USA // ?> Array ( [0] => Data Object ( [Name] => John McDonald [Age] => 65 [Address] => Address ) [1] => Data Object ( [Name] => Turgut Z. Yesilyurt [Age] => 30 [Address] => NJ, USA ) [2] => Data Object ( [Name] => Maria [Age] => 25 [Address] => NJ, USA ) ) Name : Turgut Z. Yesilyurt Age : 30 Address : NJ, USA Display Single Data ========================= Age : 30 ============================================= Default Constructor... Default Constructor... Default Constructor... ---- Manual Page -- http://www.php.net/manual/en/language.oop5.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54301 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54301&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54301&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54301&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54301&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54301&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54301&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54301&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91167) next »