Bug #74315 [Opn->Nab]: Fatal error: Declaration of test2::test() must be compatible with test1::test()

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=74315&edit=1

 ID:                 74315
 Updated by:         [email protected]
 Reported by:        spam2 at rhsoft dot net
 Summary:            Fatal error: Declaration of test2::test() must be
                     compatible with test1::test()
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Linux
 PHP Version:        7.1.3
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

If test2::test() returns anything else than an array, it would be
a violation of the LSP. It's better to catch that potential
pitfall early, and so a fatal error is raised. This is clearly not
a bug, and I don't think that a respective RFC would pass, but
feel free to submit one[1]. :)

[1] <https://wiki.php.net/rfc/howto>


Previous Comments:
------------------------------------------------------------------------
[2017-03-26 07:02:25] spam2 at rhsoft dot net

Description:
------------
it's annoying enough at all that you get warnings when method declarations are not 100% identical in case of adding param-type-hints in the underlying classes without change all extended classes at the same time but in case of return types a fatal error is just unacceptable

(and no it also don't make sense that you can't skip optional params in a extended class or add additional ones to change the behavior of the parent-call)
________________________________

unacceptable because you can't add them at all without hard breaking every dervied code while in case of the annoying warnings you can at least adopt the changes while watching errorlog and sites ar enot completly broken

[harry@srv-rhsoft:/downloads]$ php test.php
Fatal error: Declaration of test2::test() must be compatible with test1::test(): array in /mnt/data/downloads/test.php on line 2



Test script:
---------------
[harry@srv-rhsoft:/downloads]$ cat test.php
<?php
class test2 extends test1
{
 public function test()
 {

 }
}

class test1
{
 public function test(): array
 {

 }
}
?>

Expected result:
----------------
no error and in the best case even no warning at all, extedning a class and override methods in doubt always imply changed behavior with or without changing method signatures

Actual result:
--------------
Fatal error: Declaration of test2::test() must be compatible with test1::test(): array in /mnt/data/downloads/test.php on line 2


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74315&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.