View Single Post
  #16  
Old 04-08-2007, 10:14 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally Posted by Inverness View Post
Now here is the problem:
PHP Code:
---------
object1.var = {object3object4};
object2.var = object1.var;
//Objects are lost
---------
object1.var = {object3object4};
object2.var = new [object1.var.size()];
object2.var[0] = object1.var[0];
object2.var[1] = object1.var[1];
//Objects are saved 
Not true, object2.var = object1.var when object1.var is an array works just fine. It does not get lost. You are making a generalized nonexistant error from your specific problem. Your code faulters somewhere else, not on an array=array assignment.

Your problem is you are treating variables like objects. none of these objects are objects, they are just variable. someobj isnt an object, and someobj.something is just a different var, unless you say someobj = someotherobj, or someobj = new TStaticVar(); thus giving it an object definition.

The reason your properties arent copying over from file.whatever to this.whatever is because the whatevers are NOT objects.

in the above example, if object3 and object4 were specifically declared as objects, object1.var would definately reference objects, then object2.var would definately copy over object one, and it would work. the reason it doesnt work is beacuse object3 and object4 arent actually objects yet, and object3.whatever name is just the name of a variable, not a subvariable of the object.

PHP Code:
objj3.lame "hi";
objj4.lame "ho";
objj1.var = {objj3,objj4};
objj2.var = objj1.var;
echo(
objj1.var[0].lame SPC objj2.var[0].lame);
// This echo outputs nothing

objj3 = new TStaticVar();
objj4 = new TStaticVar();
objj3.lame "hi";
objj4.lame "ho";
objj1.var = {objj3,objj4};
objj2.var = objj1.var;
echo(
objj1.var[0].lame SPC objj2.var[0].lame);
// this echo outputs "hi hi" because we actually made objj3 and objj4 objects 
__________________

Last edited by Kristi; 04-08-2007 at 10:42 AM..
Reply With Quote