note 86066 added to language.oop5.late-static-bindings
| From: | lazybones_senior at osu1 dot php dot net | Date: | Wed, 01 Oct 2008 19:30:41 +0000 |
| Subject: | note 86066 added to language.oop5.late-static-bindings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144950@lists.php.net to get a copy of this message | ||
WHOA... KEEP IT SIMPLE!
Remember, when you write a class definition, you are creating a new "type" of object. And
when you extend those classes, you are creating a heirarchy. To get to the point... all the class
defs below work together to provide a solid organization of data.
<?php
abstract class Animal {
protected $type, $name;
public function __construct($aType, $aName) {
$this->type = $aType;
$this->name = $aName;
}
public function __toString() {
return "Animal [type=$this->type, name=$this->name]";
}
}
class Dog extends Animal {
public function __construct($aName) {
parent::__construct("Dog", $aName);
}
}
class Cat extends Animal {
public function __construct($aName) {
parent::__construct("Cat", $aName);
}
}
echo 'My dog: ' . (new Dog('Sam')) . '<br>';
echo 'My cat: ' . (new Cat('Fluffy')) . '<br>';
echo 'Your dog: ' . (new Dog('Walter')) . '<br>';
echo 'Yout cat: ' . (new Cat('Ginger'));
?>
My dog: Animal[type=Dog, name=Sam]
My cat: Animal[type=Cat, name=Fluffy]
Your dog: Animal[type=Dog, name=Walter]
Yout cat: Animal[type=Cat, name=Ginger]
... and notice the property called $type, is the same as using __CLASS__ in most of the previous
posts, but without the complexities of the PHP language.
----
Server IP: 69.147.83.197
Probable Submitter: 67.150.175.152
----
Manual Page -- http://www.php.net/manual/en/language.oop5.late-static-bindings.php
Edit -- https://master.php.net/note/edit/86066
Del: integrated -- https://master.php.net/note/delete/86066/integrated
Del: useless -- https://master.php.net/note/delete/86066/useless
Del: bad code -- https://master.php.net/note/delete/86066/bad+code
Del: spam -- https://master.php.net/note/delete/86066/spam
Del: non-english -- https://master.php.net/note/delete/86066/non-english
Del: in docs -- https://master.php.net/note/delete/86066/in+docs
Del: other reasons-- https://master.php.net/note/delete/86066
Reject -- https://master.php.net/note/reject/86066
Search -- https://master.php.net/manage/user-notes.php