Last active
December 13, 2015 20:38
-
-
Save rifki/4970973 to your computer and use it in GitHub Desktop.
Late Static Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SuzukiSatria120R | |
{ | |
protected static $color = 'black'; | |
protected static $topSpeed = 120; | |
protected static $type = 'Satria 120 R'; | |
protected static $tax = '2tax'; | |
public static function getColor() | |
{ | |
return static::$color; | |
} | |
public static function getTopSpeed() | |
{ | |
return static::$topSpeed; | |
} | |
public static function getType() | |
{ | |
return static::$type; | |
} | |
public static function getTax() | |
{ | |
return static::$tax; | |
} | |
public static function show() | |
{ | |
return static::getColor() . "|" . static::getTopSpeed() . "|" . static::getType() . "|" . static::getTax(); | |
} | |
} | |
class SuzukiSatriaFU extends SuzukiSatria120R | |
{ | |
protected static $topSpeed = 150; | |
protected static $type = 'Suzuki Satria FU 150'; | |
protected static $tax = '4tax'; | |
} | |
var_dump(SuzukiSatriaFU::show()); | |
var_dump(SuzukiSatria120R::show()); | |
/** output: | |
string(35) "black|150|Suzuki Satria FU 150|4tax" | |
string(27) "black|120|Satria 120 R|2tax" | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment