note 54301 deleted from language.oop5 by colder

From: Date: Sun, 19 Aug 2007 23:34:01 +0000
Subject: note 54301 deleted from language.oop5 by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129623@lists.php.net to get a copy of this message
Note Submitter: turgut85 at hotmail dot com ---- <?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...

« previous php.notes (#129623) next »