<?php include 'Toyota.php'; $t = new Toyota('Revo'); $t->setColor('เหลือง', 'dd'); $t->setEngine('3000'); echo $t->getColor(); echo "<br>"; echo "เครื่องยนต์ "; echo $t->getEngine(); echo "<br>"; echo Toyota::findName(); //call static function from toyota class
public function setTankVolume($volume) { $this->tankVolume = $volume; } public abstract function calcNumMilesOnFullTank(); } class Honda extends Car { public function calcNumMilesOnFullTank() { $miles = $this->tankVolume * 30; return $miles; } } class Toyota extends Car { public function calcNumMilesOnFullTank() { return $miles = $this->tankVolume * 33; } public function getColor() { return "beige"; } } $toyota1 = new Toyota(); $toyota1->setTankVolume(10); echo $toyota1->calcNumMilesOnFullTank(); //330 echo $toyota1->getColor(); //beige
explicitly named (usually the one on the left of the :: operator); in case of non static method calls, it is the class of the object. A "forwarding call" is a static one that is introduced by self::, parent::, static::, or, if going up in the class hierarchy, forward_static_call(). The function get_called_class() can be used to retrieve a string with the name of the called class and static:: introduces its scope. */ class Car { public static function run() { return static::getName(); } private static function getName() { return 'Car'; } } class Toyota extends Car { public static function getName() { return 'Toyota'; } } echo Car::run(); // output: Car echo Toyota::run(); // output: Toyota