Access to method who defined in trait from object

Example :

trait TaxTools {
function calculateтax ( $price ) {
return self::prop . $price ;
}
}

abstract class Alert{
    const prop = 'value__';

    abstract function limpopo();

}
class Alert2 extends Alert{
    use TaxTools;
   public  function limpopo(){
       // return self::$foo;
       return self::foo;
    }


}

$obj = new Alert2;

echo $obj->calculateтax(8); //value__8
echo '<br>';
echo $obj::calculateтax(8); //value__8

echo '<br>';
echo $obj::limpopo(); //Fatal error: Undefined class constant 'foo'

Question : Why we can access to method who defined in trait from object by :: syntax ?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s