Bug #72442 [NEW]: Return type declarations and inheritance
From: spam at bugyik dot cz
Operating system: Ubuntu 16.04
PHP version: 7.0.7
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Return type declarations and inheritance
Description:
------------
There is not possible to define return type parent object in abstract
method,
Online demo: https://3v4l.org/innXW
From documentation:
The same types are available for return type declarations as are
available for argument type declarations[1]
The parameter must be an ==INSTANCEOF== the given class or interface
name[2]
[1]
http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration
[2]
http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.types
Test script:
---------------
<?php
abstract class Entity {}
class FooEntity extends Entity {}
abstract class Repository
{
abstract public function getDetail(): Entity;
}
class FooRepository extends Repository
{
public function getDetail(): FooEntity
{
return new FooEntity;
}
}
$obj = new FooRepository();
$obj->getDetail();
Expected result:
----------------
No error expected.
Actual result:
--------------
Fatal error: Declaration of FooRepository::getDetail(): FooEntity must
be compatible with Repository::getDetail(): Entity in /in/innXW on line
18
--
Edit bug report at https://bugs.php.net/bug.php?id=72442&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72442&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72442&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72442&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72442&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72442&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72442&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72442&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72442&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72442&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72442&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72442&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72442&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72442&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72442&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72442&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72442&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72442&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72442&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72442&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72442&r=mysqlcfg
Thread (3 messages)
- spam at bugyik dot cz