Bug #80228 [NEW]: Strct types fatal error
| From: | daler445 at gmail dot com | Date: | Tue, 13 Oct 2020 08:32:51 +0000 |
| Subject: | Bug #80228 [NEW]: Strct types fatal error | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229590@lists.php.net to get a copy of this message | ||
From: daler445 at gmail dot com
Operating system: All
PHP version: 7.4.11
Package: Variables related
Bug Type: Bug
Bug description:Strct types fatal error
Description:
------------
Strict types seem to throw compile-time fatal error on retrieving data,
if you pass integer in quotes. It defines string as integer.
I guess, it's working like this:
<?php
$string = '12345';
$arr = [$string => 1];
var_dump(array_keys($arr));
which returns:
array(1) {
[0] => int(12345)
}
Bug was discovered after clear php install, no ini files was edited.
Test script:
---------------
<?php
declare(strict_types=1);
class Test {
private $storage = [];
public function setData(string $key, int $value): void
{
$this->storage[$key] = $value;
}
public function getAllData(): array
{
return array_keys($this->storage);
}
}
$test = new Test;
$test->setData('key', 1);
$test->setData('123', 2);
foreach ($test->getAllData() as $data) {
echo gettype($data) . "\n";
}
Expected result:
----------------
string string
Actual result:
--------------
string integer
--
Edit bug report at https://bugs.php.net/bug.php?id=80228&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80228&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80228&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80228&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80228&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80228&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80228&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80228&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80228&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80228&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80228&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80228&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80228&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80228&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80228&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80228&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80228&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80228&r=mysqlcfg