Edit report at https://bugs.php.net/bug.php?id=60573&edit=1
ID: 60573 Updated by: larue...@php.net Reported by: jpa...@php.net Summary: type hinting with "self" keyword causes weird errors -Status: Assigned +Status: Open Type: Feature/Change Request Package: Scripting Engine problem Operating System: *nix PHP Version: 5.3.8 Assigned To: laruence Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2011-12-20 12:31:44] larue...@php.net This is really a tough one, think about following: <?php class Foo { public function setSelf(self $s) { } } class Bar extends Foo { public function setSelf(parent $s) { } } ?> --------------------- <?php class Foo { public function setSelf(Foo $s) { } } class Bar extends Foo { public function setSelf(parent $s) { } } ----------------------- <?php class Base { } class Foo extends Base{ public function setSelf(parent $s) { } } class Bar extends Foo { public function setSelf(Base $s) { } } and more....... ------------------------------------------------------------------------ [2011-12-20 10:56:31] jpa...@php.net Description: ------------ "self" should be thought as "the class where the keyword is written in". Here is then a strange behavior using inheritance : Test script: --------------- class Foo { public function setSelf(self $s) { } } class Bar extends Foo { public function setSelf(self $s) { } } Expected result: ---------------- Strict Standards as Bar::setself() signature doesn't respect Foo::setSelf() signature. Foo's one has a type hint on Foo (using self keyword), but Bar's one on Bar (still using self keyword) : the methods then have a signature mismatch, and PHP should complain about that Actual result: -------------- Nothing happens. Trying this gives the correct E_STRICT error, correct behavior : class Foo { public function setSelf(Foo $s) { } } class Bar extends Foo { public function setSelf(Bar $s) { } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60573&edit=1