Classes in PHP5
-
-
Basic:
<?php Class MyCar { public $name; function __construct($name) { $this->name = $name; } function __destruct() { echo '*crash* this car has been destroyed'; } function drive() { echo 'Vrooooom... ' . $this->name; } } // Instance 1 $porsche = new MyCar('Porsche'); $porsche->drive(); echo ''; unset($porsche); ?>
Inheritance:
<?php Class MyCar { public $name; function __construct($name) { $this->name = $name; } function drive() { echo 'Vroooom... ' . $this->name; } } Class PorscheCar Extends MyCar { function drive() { echo 'VROOOOOOOOM... ' . $this->name; echo ''; // Call original method from parent class parent::drive(); } } $boxster = new PorscheCar('Boxster 987'); $boxster->drive(); ?>
Learn more here.
Leave a Reply
Welcome to Thronic.com
Search this Site
Miscellaneous Links
Recent Articles
- Google-like search suggestion tool
- Linux Bash Color
- Resize a div layer with javascript
- Moving a div layer with javascript
- Web Galaxy » A sci-fi browser game
- Windows 7 on Asus Eee 900 PC
- IE and PHP sessions
- Wordpress 2.8.6 Spell Check Languages
- Reset MySQL Root Password
- Linux hosts file
- IdleGuard
- Column count in SQL
- String encryption in PHP
- Alphanumeric Captcha values in PHP
- Your own numeric Captcha in PHP
