note 119580 added to language.oop5.traits
| From: | lito at eordes dot com | Date: | Mon, 11 Jul 2016 12:19:10 +0000 |
| Subject: | note 119580 added to language.oop5.traits | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205963@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 72.52.91.14
Probable Submitter: 91.117.163.184
----
Manual Page -- http://php.net/manual/en/language.oop5.traits.php
Edit -- https://master.php.net/note/edit/119580
Del: integrated -- https://master.php.net/note/delete/119580/integrated
Del: useless -- https://master.php.net/note/delete/119580/useless
Del: bad code -- https://master.php.net/note/delete/119580/bad+code
Del: spam -- https://master.php.net/note/delete/119580/spam
Del: non-english -- https://master.php.net/note/delete/119580/non-english
Del: in docs -- https://master.php.net/note/delete/119580/in+docs
Del: other reasons-- https://master.php.net/note/delete/119580
Reject -- https://master.php.net/note/reject/119580
Search -- https://master.php.net/manage/user-notes.php