php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29184 Fatal error when trying to set an object property an array
Submitted: 2004-07-15 14:52 UTC Modified: 2005-01-14 23:57 UTC
Votes:5
Avg. Score:4.2 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: jbeall at heraldic dot us Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0 OS: Linux
Private report: No CVE-ID: None
 [2004-07-15 14:52 UTC] jbeall at heraldic dot us
Description:
------------
Trying to assigned a specific array index of an object property, when __set() been defined and will catch the __set() call, causes a fatal error.

This is similar to bug 28444.  That bug has the same error, but the code that produces it is different.

Reproduce code:
---------------
class Sub
{
	function __get($prop)
	{
		echo "Property $prop called\n";
	}

	function __set($prop, $val)
	{
		echo "Property $prop set to $val\n";
	}
}


$foo = new Sub();

$foo->someProp[0] = 'apple';
echo $foo->someProp[0];

Expected result:
----------------
apple

Actual result:
--------------
Fatal error: Cannot access undefined property for object with overloaded property access in test.php on line 18

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-04 00:58 UTC] jcrawford at codebowl dot com
I am using the latest version of PHP and i have the same results when i try to do this.

array_push($object->property, $myarray);

this is not my expected results
 [2005-01-14 23:57 UTC] tony2001@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Duplicate of #28444.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 18 19:00:03 2025 UTC