Bug #70915 [NEW]: strict_types = 0 affects only string and bool

From: Date: Sat, 14 Nov 2015 16:51:47 +0000
Subject: Bug #70915 [NEW]: strict_types = 0 affects only string and bool
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197252@lists.php.net to get a copy of this message
From: duodraco@php.net Operating system: Linux (4.2.0) PHP version: 7.0.0RC7 Package: *Programming Data Structures Bug Type: Bug Bug description:strict_types = 0 affects only string and bool Description: ------------ Following docs (http://php.net/manual/pt_BR/functions.arguments.php#functions.arguments.type-declaration.strict) when we have no declaration of strict_types or it's set to 0 the default behavior for scalar types is to coerce to declared type. It's ok for string and boolean. When we set a parameter to int or float PHP throws a TypeError - the expected behavior for strict_types = 1. When strict_types is set to 1 everything runs as expected. Test script: --------------- declare(strict_types = 0); function test(int $grade) { return $grade >= 7 ? 'X' : 'Y'; } willInternTurnEmployee(8); //'Pass' and OK echo willInternTurnEmployee('Really?'); //Expected: 'Fail', string converted to int //TypeError thrown Expected result: ---------------- Y Actual result: -------------- Fatal error: Uncaught TypeError: Argument 1 passed to willInternTurnEmployee() must be of the type integer, string given, called in /path/to/Projects/php7-demo/app/x.php on line 12 and defined in /path/to/Projects/php7-demo/app/x.php:4 Stack trace: #0 /path/to/Projects/php7-demo/app/x.php(12): willInternTurnEmployee('Really?') #1 {main} thrown in /path/to/Projects/php7-demo/app/x.php on line 4 -- Edit bug report at https://bugs.php.net/bug.php?id=70915&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70915&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70915&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70915&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70915&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70915&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70915&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70915&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70915&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70915&r=support Expected behavior: https://bugs.php.net/fix.php?id=70915&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70915&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70915&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70915&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70915&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70915&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70915&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70915&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70915&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70915&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70915&r=mysqlcfg

« previous php.bugs (#197252) next »