Bug #76973 [Com]: Return type that is alias of base class' type should be compatible

From: Date: Thu, 04 Oct 2018 17:33:01 +0000
Subject: Bug #76973 [Com]: Return type that is alias of base class' type should be compatible
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217414@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76973&edit=1

 ID:                 76973
 Comment by:         spam2 at rhsoft dot net
 Reported by:        ayg at aryeh dot name
 Summary:            Return type that is alias of base class' type should
                     be compatible
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Ubuntu
 PHP Version:        7.2.10
 Block user comment: N
 Private report:     N

 New Comment:

are you out of linebreaks and spaces or why do you need to post such unreadable sample code?


Previous Comments:
------------------------------------------------------------------------
[2018-10-04 17:26:14] ayg at aryeh dot name

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 this bug report at https://bugs.php.net/bug.php?id=76973&edit=1


Thread (7 messages)

« previous php.bugs (#217414) next »