php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1304 Assignment to members of object in an array of objects
Submitted: 1999-04-08 01:32 UTC Modified: 1999-06-20 20:30 UTC
From: maarnold at gte dot net Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.5 OS: linux
Private report: No CVE-ID: None
 [1999-04-08 01:32 UTC] maarnold at gte dot net
I've tried a work around to bug #1182, but I am getting flaky results.
The situation is...
/*
 * Code snippet #1
 */
class DbFldC
	{
	var Name;
	var Label;
	}
class DbTblC
	{
	var Fields;
	}
$DbFld = new DbFldC;
$DbFld->Name = "id";
$DbTbl = new DbTblC;
$DbTbl->Fields[] = $DbFld;

Bug 1182 says that...
$DbTbl->Fields[ 0 ]->Label = "Sequence No";
...yields a parser error, which is true;

My work around is...
/* 
 * Code snippet #2
 */
$TmpFld = $DbTbl->Fields[ 0 ];
$TmpFld->Label = "Sequence No.";

Unfortunately, this doesn't always work. Sometimes the assignment "sticks" and sometimes it doesn't. Does $TmpFld reference the original object to which it was assigned, or does the assignment make a copy of the original object (to which $TmpFld not points)? Sometimes it does, and sometimes it doesn't.

Let's say the Code snippet #1 and #2 have been executed. Then the following code is executed...

printf( "Name is %s. Label is %s.<BR>\n", $TmpFld->Name, $TmpFld->Label );
$TmpFld2 = $DbTbl->Fields[ 0 ];
printf( "Name is %s. Label is %s.<BR>\n", $TmpFld2->Name, $TmpFld2->Label );

...This yields the following output...

Name is id. Label is Sequence No.
Name is id. Label is


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-20 20:30 UTC] jim at cvs dot php dot net
Assignment makes a copy, not a reference (and
the original problem will be solved in PHP4).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 30 22:01:28 2024 UTC