php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74075 type hints handle NULL always in strict mode
Submitted: 2017-02-10 12:41 UTC Modified: 2017-02-10 12:56 UTC
From: spam2 at rhsoft dot net Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.0.15 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: spam2 at rhsoft dot net
New email:
PHP Version: OS:

 

 [2017-02-10 12:41 UTC] spam2 at rhsoft dot net
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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-10 12:56 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2017-02-10 12:56 UTC] nikic@php.net
Duplicate of bug #70519.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC