note 116907 added to language.oop5.traits
| From: | (!) | Date: | Thu, 19 Mar 2015 10:48:28 +0000 |
| Subject: | note 116907 added to language.oop5.traits | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201987@lists.php.net to get a copy of this message | ||
Keep in mind; "final" keyword is useless in traits when directly using them, unlike
extending classes / abstract classes.
<?php
trait Foo {
final public function hello($s) { print "$s, hello!"; }
}
class Bar {
use Foo;
// Overwrite, no error
final public function hello($s) { print "hello, $s!"; }
}
abstract class Foo {
final public function hello($s) { print "$s, hello!"; }
}
class Bar extends Foo {
// Fatal error: Cannot override final method Foo::hello() in ..
final public function hello($s) { print "hello, $s!"; }
}
?>
But this way will finalize trait methods as expected;
<?php
trait FooTrait {
final public function hello($s) { print "$s, hello!"; }
}
abstract class Foo {
use FooTrait;
}
class Bar extends Foo {
// Fatal error: Cannot override final method Foo::hello() in ..
final public function hello($s) { print "hello, $s!"; }
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 37.77.30.193
----
Manual Page -- http://php.net/manual/en/language.oop5.traits.php
Edit -- https://master.php.net/note/edit/116907
Del: integrated -- https://master.php.net/note/delete/116907/integrated
Del: useless -- https://master.php.net/note/delete/116907/useless
Del: bad code -- https://master.php.net/note/delete/116907/bad+code
Del: spam -- https://master.php.net/note/delete/116907/spam
Del: non-english -- https://master.php.net/note/delete/116907/non-english
Del: in docs -- https://master.php.net/note/delete/116907/in+docs
Del: other reasons-- https://master.php.net/note/delete/116907
Reject -- https://master.php.net/note/reject/116907
Search -- https://master.php.net/manage/user-notes.php