note 126250 added to faq.using
| From: | kleeh at bellsouth dot net | Date: | Sat, 17 Jul 2021 20:14:27 +0000 |
| Subject: | note 126250 added to faq.using | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216614@lists.php.net to get a copy of this message | ||
What is the point of designating "protected" or "private" methods in a TRAIT?
Referencing Example #6 Changing Method Visibility
<?php
trait HelloWorld {
public function sayHello() {
echo 'Hello World!';
}
}
// Change visibility of sayHello
class MyClass1 {
use HelloWorld { sayHello as protected; }
}
// Alias method with changed visibility
// sayHello visibility not changed
class MyClass2 {
use HelloWorld { sayHello as private myPrivateHello; }
}
I don't understand the point of the "private" in the "using class" at all.
And I extended the MyClass1, trying to use the 'protected' version and got the error about
not being able to use a protected class when I instantiated the extending class. This looks like an
example of " just because you can doesn't mean you should ...".
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 97.82.59.26)
----
Manual Page -- https://php.net/manual/en/faq.using.php
Edit -- https://main.php.net/note/edit/126250
Del: integrated -- https://main.php.net/note/delete/126250/integrated
Del: useless -- https://main.php.net/note/delete/126250/useless
Del: bad code -- https://main.php.net/note/delete/126250/bad+code
Del: spam -- https://main.php.net/note/delete/126250/spam
Del: non-english -- https://main.php.net/note/delete/126250/non-english
Del: in docs -- https://main.php.net/note/delete/126250/in+docs
Del: other reasons-- https://main.php.net/note/delete/126250
Reject -- https://main.php.net/note/reject/126250
Search -- https://main.php.net/manage/user-notes.php