Bug #78677 [Opn->Nab]: Interface declaration of ... unexpected behavior
| From: | cmb@php.net | Date: | Thu, 17 Oct 2019 08:02:40 +0000 |
| Subject: | Bug #78677 [Opn->Nab]: Interface declaration of ... unexpected behavior | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223219@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78677&edit=1
ID: 78677
Updated by: cmb@php.net
Reported by: pavel at bunaev dot ru
Summary: Interface declaration of ... unexpected behavior
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Programming Data Structures
Operating System: 18.04.1-Ubuntu
PHP Version: 7.2.23
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
See <https://www.php.net/manual/en/migration72.new-features.php#migration72.new-features.param-type-widening>.
Previous Comments:
------------------------------------------------------------------------
[2019-10-17 07:41:20] pavel at bunaev dot ru
Description:
------------
The interface allows you to change the type of variable in an incompatible direction.
In versions php 7.0+ and 7.1-, we could specify in the interface with what types of data we will
work in the method.
And at the kernel level, be sure that by implementing the interface the signature will not change.
In version php 7.2+ and 7.3+, this has changed and there was no announcement ..
We can create an interface and expect in the signature that the method will work with certain
arguments
but in fact we can transfer anything
OS linux
version php 7.2+
version php 7.1- is ok
Test script:
---------------
<?php
interface IBaz {};
interface IFoo {
public function simple(IBaz $a);
}
class CFoo implements IFoo {
public function simple($a){
var_dump($a);
}
}
$cFoo = new CFoo();
$cFoo->simple('vbvc');
Expected result:
----------------
<br />
<b>Fatal error</b>: Declaration of CFoo::simple($a) must be compatible with
IFoo::simple(IBaz $a) in <b>[...][...]</b> on line <b>7</b><br />
Actual result:
--------------
string(4) "vbvc"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78677&edit=1