|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79477 casting object into array creates references
Submitted: 2020-04-14 16:42 UTC Modified: 2020-04-15 07:52 UTC
From: david at grudl dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.4.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
41 - 23 = ?
Subscribe to this entry?

 [2020-04-14 16:42 UTC] david at grudl dot com
See the code below. It should print 'default value', but when I'll create property $obj->{1}, it prints 'new value'.

This affects PHP >= 7.2 and objects where property key is integer.

Test script:

class Test
	public $prop = 'default value';

$obj = new Test;
// $obj->{1} = null;

$arr = (array) $obj;
$arr['prop'] = 'new value';

echo $obj->prop;  


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-14 16:54 UTC] david at grudl dot com
-Package: Output Control +Package: Scripting Engine problem
 [2020-04-14 16:54 UTC] david at grudl dot com
fixed package
 [2020-04-15 07:52 UTC]
-Status: Open +Status: Verified
 [2020-04-15 09:22 UTC]
Automatic comment on behalf of
Log: Fixed bug #79477
 [2020-04-15 09:22 UTC]
-Status: Verified +Status: Closed
 [2020-04-15 16:53 UTC] david at grudl dot com
Wow, it was fast, thanks :)
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 13:05:55 2022 UTC