|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-04-01 12:47 UTC] php-svn at helio dot arq dot br
Description:
------------
I'm trying Traits in php-trunk version.
In a give moment, I tried to change visibility in a alias trait's method.
Test script:
---------------
trait Foo {
public static function lol() {
echo 'Foo!';
}
}
class Boo {
use Foo {
Foo::lol as dontKnow;
dontKnow as protected;
}
}
$boo = new Boo();
$boo->dontKnow();
Expected result:
----------------
Fatal error: Call to protected method Boo::dontKnow() from context '' in %s on line %d
Actual result:
--------------
Foo!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 11:00:01 2025 UTC |
class Boo { use Foo { Foo::lol as dontKnow; dontKnow as protected; } } To me this would do the following: Use "Foo", set "Foo:lol" as "dontKnow", and then set "dontKnow" as "protected" Meaning that I should be able to call $boo->lol, $boo->dontKnow, or $boo->protected to accomplish the same thing. Otherwise it should throw a method does not exist error if the "as" is supposed to rename the function.Hm, today I feel like it is not a good idea to allow use Foo { Foo::lol as dontKnow; dontKnow as protected; } Because we will end up with chains like this: use Foo { Foo::lol as dontKnow; dontKnow as foo; foo as bar; bar as baz; } And I do not see the use case for it, while I see readability problems. This is all equivalent to: use Foo { Foo::lol as dontKnow; Foo::lol as foo; Foo::lol as bar; Foo::lol as baz; } Which IMHO is a lot clearer. Every level of indirection is another level of added complexity, and I do not see a relevant use case at the moment. So, I will regard this as something that should not work. Not sure yet how to design it properly. Will look at it.