|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-03-28 13:37 UTC] spam2 at rhsoft dot net
Description:
------------
[harry@rh:/downloads]$ php test.php
Fatal error: Uncaught TypeError: Argument 1 passed to test() must be of the type string, integer given, called in /mnt/data/downloads/test.php on line 11 and defined in /mnt/data/downloads/test.php:13
Stack trace:
#0 /mnt/data/downloads/test.php(11): test(1, 'c')
#1 {main}
thrown in /mnt/data/downloads/test.php on line 13
____________________________________
why in the world is the array-key silently cased to an integer - if that would have been the intention the code would be 1=>'c' instead '1'=>'c'
besides that this breaks strict mode that conversion are useless cpy-cycles
Test script:
---------------
[harry@rh:/downloads]$ cat test.php
<?php declare(strict_types=1);
$arr =
[
'a' => 'a',
'b' => 'b',
'1' => 'c',
'2' => 'd'
];
foreach($arr as $key=>$value)
{
test($key, $value);
}
function test(string $a, string $b)
{
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 03:00:01 2025 UTC |
any by all respect it's idiotic that you cast something which is a string by intention to a integer and force me to do another explicit cast back to string foreach($password_references as $version=>$hash) { $generated = $cl_api->user_db->generate_password_hash('autotest_pwd', (string)$version);