Skip to content

Instantly share code, notes, and snippets.

@rifki
Last active December 13, 2015 20:38
Show Gist options
  • Save rifki/4970973 to your computer and use it in GitHub Desktop.
Save rifki/4970973 to your computer and use it in GitHub Desktop.
Late Static Binding
<?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