Bug #70519 [Opn->Nab]: strict_types=0 does not work with NULL

From: Date: Thu, 17 Sep 2015 12:39:02 +0000
Subject: Bug #70519 [Opn->Nab]: strict_types=0 does not work with NULL
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196056@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70519&edit=1

 ID:                 70519
 Updated by:         bwoebi@php.net
 Reported by:        vincent dot guth at gmail dot com
 Summary:            strict_types=0 does not work with NULL
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   Linux
 PHP Version:        7.0.0RC3
 Block user comment: N
 Private report:     N

 New Comment:

As defined by the RFC, this is totally intentional.

See: https://wiki.php.net/rfc/scalar_type_hints_v5#behaviour_of_weak_type_checks


Previous Comments:
------------------------------------------------------------------------
[2015-09-17 12:10:55] vincent dot guth at gmail dot com

Description:
------------
declare(strict_types=0); does not work with NULL value when using argument type declarations (see
test script).


Test script:
---------------
php7 -r 'declare(strict_types=0); function test(string $s) {var_dump($s);} test(123);'
php7 -r 'declare(strict_types=0); function test(string $s) {var_dump($s);} test(NULL);'


Expected result:
----------------
string(3) "123"
string(0) ""

Actual result:
--------------
string(3) "123"
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to test() must be of the type string, null
given, called in Command line code on line 1 and defined in Command line code:1
Stack trace:
#0 Command line code(1): test(NULL)
#1 {main}
  thrown in Command line code on line 1


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



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


Thread (4 messages)

« previous php.bugs (#196056) next »