note 28214 added to language.oop
| From: | tomcat at techie dot com | Date: | Mon, 06 Jan 2003 12:39:30 +0000 |
| Subject: | note 28214 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41719@lists.php.net to get a copy of this message | ||
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?).
--
http://www.php.net/manual/en/language.oop.php
http://master.php.net/manage/user-notes.php?action=edit+28214
http://master.php.net/manage/user-notes.php?action=delete+28214
http://master.php.net/manage/user-notes.php?action=reject+28214