[PHP-BUG] Req #75058 [NEW]: Check type on return of typehint arguments passed by reference.

[email protected] ("email at davekok dot nl") Thu, 10 Aug 2017 13:27:35 GMT
Newsgroups php.standards
Message-ID <[email protected]>
From:             email at davekok dot nl
Operating system: any
PHP version:      Next Minor Version
Package:          PHP Language Specification
Bug Type:         Feature/Change Request
Bug description:Check type on return of typehint arguments passed by reference.

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 bug report at https://bugs.php.net/bug.php?id=75058&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=75058&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=75058&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=75058&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=75058&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=75058&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=75058&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=75058&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=75058&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=75058&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=75058&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=75058&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=75058&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=75058&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75058&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=75058&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=75058&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=75058&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75058&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=75058&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=75058&r=mysqlcfg