php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47154 Object properties unset after setting.
Submitted: 2009-01-19 21:16 UTC Modified: 2011-11-15 23:23 UTC
Votes:5
Avg. Score:4.2 ± 1.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: onerax at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3 OS: Windows
Private report: No CVE-ID: None
 [2009-01-19 21:16 UTC] onerax at gmail dot com
Description:
------------
After setting object properties on one line, object is still empty on 
the next. Inheritance, multiple namespaces, and passing arrays by 
reference are involved.





Reproduce code:
---------------
http://helios-emu.org/arraytest.txt

keep in mind this is not the actual code, and does not reproduce the problem by itself. To reproduce the problem you have to separate each class into a separate file and separate them out into two separate namespaces. I have the original code that I uncovered this in and can e-mail it upon a developer's request, but I will not make it public.

Expected result:
----------------
The object in which the properties are set contain data.

Actual result:
--------------
The object in which the properties are set do not contain data.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-20 16:51 UTC] onerax at gmail dot com
Here's a section of the actual code piece, and the output of all 
involved variables after the routine.

CODE::
<?php
Namespace xBB\Database;
require_once('./Core/Database/EntityQueries.class.php');

class UserQueries extends EntityQueries
{
	public function Fill($User, Array &$Data)
	{
		parent::Fill($User, $Data);
		$User->Password	= $Data['Password'];
		$User->LastLogin	= $Data['LastLogin'];
		$User->LastIp	= $Data['LastIp'];

		require_once('./Core/Entities/Profile.class.php');
		$User->Profile		= new 
\xBB\Entities\Profile();
		$User->Profile->UserId	= $Data['EntityId'];

		$this->Database->Profiles->Fill($User->Profile, 
$Data);
		if(sizeof($Data)>1){
		die(print_r($User).print_r($User-
>Profile).print_r($Data));
		}
	}
...


OUTPUT::
xBB\Entities\User Object ( [Password] => [LastLogin] => [Profile] => 
xBB\Entities\Profile Object ( [UserId] => [FirstName] => [MiddleName] 
=> [LastName] => [Avatar] => [Alias] => [Gender] => [Signature] => ) 
[LastIp] => [EntityId] => [Name] => [Description] => [Updated] => 
[Created] => [Parent] => [Owner] => ) xBB\Entities\Profile Object ( 
[UserId] => [FirstName] => [MiddleName] => [LastName] => [Avatar] => 
[Alias] => [Gender] => [Signature] => ) Array ( [EntityId] => 
USER_4974b612242741.58553835 [Password] => test [LastLogin] => 
[LastIp] => [Name] => test [Description] => [Updated] => [Created] => 
2009-01-19 17:19:14 [Parent] => [Owner] => [UserId] => 
USER_4974b612242741.58553835 [FirstName] => [MiddleName] => 
[LastName] => [Avatar] => [Alias] => [Gender] => [Signature] => ) 
111Page Generation Time:: 0.093775 seconds
 [2009-01-20 23:12 UTC] onerax at gmail dot com
It also seems that if I set the values in the object manually - in 
the above example, $User->Password = 'notest', then the property is 
set. If I do the same to the array $Data, $Data['Password'] = 
'notest', It does not set the existing Password index, rather it 
creates a second Password index, which is shown in print_r below.

Array ( [EntityId] => USER_4974b612242741.58553835 [Password] => test 
[LastLogin] => [LastIp] => [Name] => test [Description] => [Updated] 
=> [Created] => 2009-01-19 17:19:14 [Parent] => [Owner] => [UserId] 
=> USER_4974b612242741.58553835 [FirstName] => [MiddleName] => 
[LastName] => [Avatar] => [Alias] => [Gender] => [Signature] => 
[Password] => notest ) 111Page Generation Time:: 0.09224 seconds

A single array with two "Password" entries...strange, yes? =)
 [2009-01-21 22:21 UTC] onerax at gmail dot com
I've found a workaround for this problem.

Using extract($Data) I was able to assign $User->Password to the 
resulting $Password variable and get the correct value in place.
 [2011-11-15 23:23 UTC] felipe@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 [2011-11-15 23:23 UTC] felipe@php.net
-Status: Open +Status: Bogus -PHP Version: 6CVS-2009-01-19 (snap) +PHP Version: 5.3
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 17:01:33 2025 UTC