Bug #74075 [NEW]: type hints handle NULL always in strict mode
| From: | spam2 at rhsoft dot net | Date: | Fri, 10 Feb 2017 12:41:49 +0000 |
| Subject: | Bug #74075 [NEW]: type hints handle NULL always in strict mode | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-207246@lists.php.net to get a copy of this message | ||
From: spam2 at rhsoft dot net
Operating system:
PHP version: 7.0.15
Package: Scripting Engine problem
Bug Type: Bug
Bug description:type hints handle NULL always in strict mode
Description:
------------
why in the world behaves a user function with a scalar type hint always
like declare(strict_types=1) has been set while builtin-functions have
that behavior only when strict mode is really enabled
frankly that breaks a lot of code when you try to introduce scalar type
hints to get rid of explicit type casting randomly and defeats the whole
purpuse of type hints in function definitions and that is a MAJOR
problem
Test script:
---------------
________________________________________________________
OK
[harry@srv-rhsoft:/downloads]$ cat test.php
<?php
$test = NULL;
echo trim($test);
?>
[harry@srv-rhsoft:/downloads]$ php test.php
[harry@srv-rhsoft:/downloads]$
[harry@srv-rhsoft:/downloads]$ cat test.php
<?php declare(strict_types=1);
$test = NULL;
echo trim($test);
?>
[harry@srv-rhsoft:/downloads]$ php test.php
Fatal error: Uncaught TypeError: trim() expects parameter 1 to be
string, null given in /mnt/data/downloads/test.php:3
Stack trace:
#0 /mnt/data/downloads/test.php(3): trim(NULL)
#1 {main}
thrown in /mnt/data/downloads/test.php on line 3
________________________________________________________
COMPLETLY BROKEN BEHAVIOR:
[harry@srv-rhsoft:/downloads]$ cat test.php
<?php
$test = NULL;
echo test($test);
function test(string $input)
{
}
?>
[harry@srv-rhsoft:/downloads]$ php test.php
Fatal error: Uncaught TypeError: Argument 1 passed to test() must be of
the type string, null given, called in /mnt/data/downloads/test.php on
line 3 and defined in /mnt/data/downloads/test.php:5
Stack trace:
#0 /mnt/data/downloads/test.php(3): test(NULL)
#1 {main}
thrown in /mnt/data/downloads/test.php on line 5
--
Edit bug report at https://bugs.php.net/bug.php?id=74075&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74075&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74075&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74075&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74075&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74075&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74075&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74075&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74075&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74075&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74075&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74075&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74075&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74075&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74075&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74075&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74075&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74075&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74075&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74075&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74075&r=mysqlcfg