|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-01-17 08:53 UTC] zaq178miami at gmail dot com
Description: ------------ It seems to be that is_nan check fails or sth like that as when passing NAN to as an int parameter it silently casted to int(0). While int(0) is valid result for explicit (int)NAN cast, according to Andrea (https://wiki.php.net/rfc/zpp_fail_on_overflow). As already discussed on SO (http://chat.stackoverflow.com/transcript/message/35136128#35136128) it might be just a musl bug, but maybe we should check what NAN do we have and maybe alter config scripts and/or php_get_nan() accordingly? Here is runnable snippet: https://3v4l.org/m7hpq Test script: --------------- <?php function test(int $test) { var_dump($test); } test(NAN); Expected result: ---------------- Fatal error: Uncaught TypeError: Argument 1 passed to test() must be of the type integer, float given, called in /in/m7hpq on line 6 and defined in /in/m7hpq:2 Stack trace: #0 /in/m7hpq(6): test(NAN) #1 {main} thrown in /in/m7hpq on line 2 Actual result: -------------- int(0) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 17:00:02 2025 UTC |
Okay, I got an Alpine install up and running in a VM and I can reproduce this for php-src master: localhost:~/php-src# uname -a; sapi/cli/php -v; sapi/cli/php -r 'function foo(in t $x) {} var_dump(foo(NAN));' Linux localhost 4.4.45-0-virtgrsec #1-Alpine SMP Thu Jan 26 14:32:43 GMT 2017 x86_64 Linux PHP 7.2.0-dev (cli) (built: Feb 4 2017 23:35:47) ( NTS DEBUG ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies NULL Whereas on macOS: Andreas-MacBook-Air:php-src ajf$ uname -a; sapi/cli/php -v; sapi/cli/php -r 'function foo(int $x) {} var_dump(foo(NAN));' Darwin Andreas-MacBook-Air.local 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64 PHP 7.2.0-dev (cli) (built: Jan 31 2017 21:23:57) ( NTS DEBUG ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.2.0-dev, Copyright (c) 1999-2017, by Zend Technologies Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type integer, float given, called in Command line code on line 1 and defined in Command line code:1 Stack trace: #0 Command line code(1): foo(NAN) #1 {main} thrown in Command line code on line 1