|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-02-10 12:56 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2017-02-10 12:56 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Jan 08 23:00:01 2026 UTC |
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