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

From: Date: Sat, 14 Nov 2015 16:54:50 +0000
Subject: Bug #70915 [Com]: strict_types = 0 affects only string and bool
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197253@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70915&edit=1 ID: 70915 Comment by: duodraco@php.net Reported by: duodraco@php.net Summary: strict_types = 0 affects only string and bool Status: Open Type: Bug Package: *Programming Data Structures Operating System: Linux (4.2.0) PHP Version: 7.0.0RC7 Block user comment: N Private report: N New Comment: It affects both 'Scalar Type Hints' and 'Return Type Declarations' Previous Comments: ------------------------------------------------------------------------ [2015-11-14 16:51:46] duodraco@php.net 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 this bug report at https://bugs.php.net/bug.php?id=70915&edit=1

« previous php.bugs (#197253) next »