note 28214 deleted from language.oop by aidan

From: Date: Sat, 03 Jul 2004 14:55:16 +0000
Subject: note 28214 deleted from language.oop by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72453@lists.php.net to get a copy of this message
Note Submitter: tomcat@techie.com ---- The fact that PHP does not support variable types, leads to new opportunities. You can make an object-collection with different classes of objects, extremely easily (pay attention to posession collection of merchant object): [example] class user { var $login; var $email; var $password; function user ( $login, $email, $password ) { $this->login = $login; $this->email = $email; $this->password=$password; } } class house { var $price; var $area; function house () { $this->price = 10000000000; } } class car { var $price; var $speed; var $length; var $color; function car () { $this->speed = 300; } } class merchant { var $age; var $personality; var $posession; function merchant () { $this->age=27; } } $oMerchant = new merchant(); $oMerchant->personality = new user("name","pas","email"); $oMerchant->posession[] = new car(); $oMerchant->posession[] = new house(); echo " <pre> car-speed: ".$oMerchant->posession[0]->speed." house-price: ".$oMerchant->posession[1]->price." </pre> " [/example] It's real cute, how easy it is compared to strictly-typed languages (well, it's less clean but so is everything in non-typed languages, right?).

« previous php.notes (#72453) next »