Req #60573 [Com]: type hinting with "self" keyword causes weird errors
| From: | laruence@php.net | Date: | Tue, 20 Dec 2011 16:04:08 +0000 |
| Subject: | Req #60573 [Com]: type hinting with "self" keyword causes weird errors | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-165998@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
Comment by: laruence@php.net
Reported by: jpauli@php.net
Summary: type hinting with "self" keyword causes weird errors
Status: Assigned
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
New Comment:
a patch for php 5.4 was submitted, since 5.4 will generate detailed info about the
prototype argument list, so this defect is more significant for 5.4.
and Tyrael suggest commit this only after 5.4.0 release. so leave this open, I
will commit later.
thanks
Previous Comments:
------------------------------------------------------------------------
[2011-12-20 16:01:42] laruence@php.net
The following patch has been added/updated:
Patch Name: bug60573.phpt
Revision: 1324396902
URL: https://bugs.php.net/patch-display.php?bug=60573&patch=bug60573.phpt&revision=1324396902
------------------------------------------------------------------------
[2011-12-20 16:01:15] laruence@php.net
The following patch has been added/updated:
Patch Name: bug60573.patch
Revision: 1324396875
URL: https://bugs.php.net/patch-display.php?bug=60573&patch=bug60573.patch&revision=1324396875
------------------------------------------------------------------------
[2011-12-20 12:53:38] laruence@php.net
I have a patch now, will apply it after do careful testings
------------------------------------------------------------------------
[2011-12-20 12:31:44] laruence@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] 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