Req #60573 [Opn]: type hinting with "self" keyword causes weird errors

From: Date: Tue, 20 Dec 2011 12:31:45 +0000
Subject: Req #60573 [Opn]: type hinting with "self" keyword causes weird errors
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-165988@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60573&edit=1 ID: 60573 Updated by: laruence@php.net Reported by: jpauli@php.net Summary: type hinting with "self" keyword causes weird errors Status: Open Type: Feature/Change Request Package: Scripting Engine problem Operating System: *nix PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: 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....... Previous Comments: ------------------------------------------------------------------------ [2011-12-20 10:56:31] jpauli@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

« previous php.bugs (#165988) next »