|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80228 Strct types fatal error
Submitted: 2020-10-13 08:32 UTC Modified: 2020-10-13 08:40 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: daler445 at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Variables related
PHP Version: 7.4.11 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: daler445 at gmail dot com
New email:
PHP Version: OS:


 [2020-10-13 08:32 UTC] daler445 at gmail dot com
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:
$string = '12345';
$arr = [$string => 1];

which returns:
array(1) {
    [0] => int(12345)

Bug was discovered after clear php install, no ini files was edited.

Test script:
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 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-13 08:40 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-10-13 08:40 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is documented[1] behavior:

| Additionally the following key casts will occur:
| Strings containing valid decimal integers, unless the number is
| preceded by a + sign, will be cast to the integer type.

[1] <>
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Nov 30 17:01:30 2023 UTC