|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-10-13 01:13 UTC] requinix@php.net
-Status: Open
+Status: Wont fix
-Package: PHP Language Specification
+Package: Scripting Engine problem
[2015-10-13 01:13 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 10:00:01 2026 UTC |
Description: ------------ I think there might still be some minor changes to be done to integer type hinting, in weak mode. First of all, the current behavior is different whether you pass an invalid string, or an invalid float: function test(int $a) {} test("3 dogs"); // PHP Notice test(3.5); // silent discard of the fraction Both result in a truncated piece of information, but one yields a PHP notice while the other doesn't. ---- That being said, IMHO even in weak mode, I think it's a mistake not to throw a TypeError when the type conversion involves truncation. This is what I would suggest: test(3); test(3.0); test(3.1); // TypeError (currently: silent discard) test('3'); test('3 dogs'); // TypeError (currently: PHP notice) And no changes in strict mode: declare(strict_types=1); test(3); test(3.0); // TypeError test(3.1); // TypeError test('3'); // TypeError test('3 dogs'); // TypeError Basically, IMHO again, weak mode should allow other types *as long as they can be safely converted, without truncation*. Anything else just opens the door to weird, difficult to track bugs.