Bug #76973 [NEW]: Return type that is alias of base class' type should be compatible
From: ayg at aryeh dot name
Operating system: Ubuntu
PHP version: 7.2.10
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Return type that is alias of base class' type should be compatible
Description:
------------
If a base class defines a method with a return type declaration, and a
derived class overrides the method, the return type in the derived class
must be the same as in the base class. However, if the return types are
classes that are aliases of one another, it should be considered the
same. Currently it is not.
Test script:
---------------
<?php
class A {}
class_alias( "A", "B" );
class C { function f() : A { return new A; } }
class D extends C { function f() : B { return new B; } }
Expected result:
----------------
No error
Actual result:
--------------
PHP Fatal error: Declaration of D::f(): B must be compatible with
C::f(): A in Standard input code on line 5
--
Edit bug report at https://bugs.php.net/bug.php?id=76973&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76973&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76973&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76973&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76973&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76973&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76973&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76973&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76973&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76973&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76973&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76973&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76973&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76973&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76973&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76973&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76973&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76973&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76973&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76973&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76973&r=mysqlcfg
Thread (7 messages)
- ayg at aryeh dot name