Req->Bug #75058 [Opn->Nab]: Check type on return of typehint arguments passed by reference.
| From: | requinix@php.net | Date: | Thu, 10 Aug 2017 13:57:43 +0000 |
| Subject: | Req->Bug #75058 [Opn->Nab]: Check type on return of typehint arguments passed by reference. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210585@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75058&edit=1
ID: 75058
Updated by: requinix@php.net
Reported by: email at davekok dot nl
Summary: Check type on return of typehint arguments passed by
reference.
-Status: Open
+Status: Not a bug
-Type: Feature/Change Request
+Type: Bug
-Package: PHP Language Specification
+Package: *General Issues
Operating System: any
PHP Version: Next Minor Version
Block user comment: N
Private report: N
New Comment:
That.
Previous Comments:
------------------------------------------------------------------------
[2017-08-10 13:34:06] kelunik@php.net
This is not a bug. Parameters are checked on input and shouldn't be used for output.
The thing you want are typed variables, which do not exist, because it would have to be checked on
every assignment, not only on return.
------------------------------------------------------------------------
[2017-08-10 13:27:31] email at davekok dot nl
Description:
------------
When declaring a function with a type hinted argument passed by reference, the argument's type
is not checked on the function's return. I would expect that when calling a function with a
type hinted argument passed by reference. That the variable used will still contain data of that
type when the function finishes.
Test script:
---------------
<?php
function foo(int &$i)
{
$i = "string"; // incorrect type
}
function bar(?int &$i)
{
$i = null; // correct type
}
function baz(?int &$i)
{
$i = 4; // correct type
}
Expected result:
----------------
A error is thrown on foo's return stating that the variable $i has an incorrect type.
Actual result:
--------------
The code continues as if all is well.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75058&edit=1