note 119580 rejected from language.oop5.traits by cmb
| From: | cmb@php.net | Date: | Sun, 01 Dec 2019 08:55:56 +0000 |
| Subject: | note 119580 rejected from language.oop5.traits by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213332@lists.php.net to get a copy of this message | ||
Note Submitter: lito at eordes dot com
----
trait static methods can be called without need to implement into a main class.
<?php
trait Vehicle {
public static function wheels() {
return 4;
}
}
var_dump(Vehicle::wheels()); // 4
?>
but you can not instantiate a trait:
<?php
trait Vehicle {
public function wheels() {
return 4;
}
}
var_dump((new Vehicle)->wheels()); // Fatal error: Cannot instantiate trait Vehicle
?>
For me, it's strange.