Bug #74075 [Opn->Dup]: type hints handle NULL always in strict mode

From: Date: Fri, 10 Feb 2017 12:56:46 +0000
Subject: Bug #74075 [Opn->Dup]: type hints handle NULL always in strict mode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207248@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74075&edit=1

 ID:                 74075
 Updated by:         nikic@php.net
 Reported by:        spam2 at rhsoft dot net
 Summary:            type hints handle NULL always in strict mode
-Status:             Open
+Status:             Duplicate
 Type:               Bug
 Package:            Scripting Engine problem
 PHP Version:        7.0.15
 Block user comment: N
 Private report:     N

 New Comment:

Duplicate of bug #70519.


Previous Comments:
------------------------------------------------------------------------
[2017-02-10 12:41:42] 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




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74075&edit=1


Thread (2 messages)

« previous php.bugs (#207248) next »