Bug #73152 [NEW]: Hint of return type in PHP works unexpected way.
From: roman at litgroup dot ru
Operating system: Linux
PHP version: 7.0.11
Package: *General Issues
Bug Type: Bug
Bug description:Hint of return type in PHP works unexpected way.
Description:
------------
Hint of return type in PHP works unexpected way.
It's not possible to change hint of return type to a more concrete
subtype.
Test script:
---------------
interface Person {/* _ */}
interface PersonFactory
{
public function createPerson(): Person;
}
class Customer implements Person {/* _ */}
class CustomerFactory implements PersonFactory
{
public function createPerson(): Customer // PHP Fatal error:
{ // Declaration of
CustomerFactory::createPerson(): Customer
return new Customer(); // must be compatible with
PersonFactory::createPerson(): Person
}
}
--
Edit bug report at https://bugs.php.net/bug.php?id=73152&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73152&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73152&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73152&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73152&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73152&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73152&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73152&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73152&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73152&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73152&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73152&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73152&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73152&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73152&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73152&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73152&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73152&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73152&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73152&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73152&r=mysqlcfg
Thread (2 messages)
- roman at litgroup dot ru