Re: [PHP] Unable to return object references from functions
Hello, Tom Rogers wrote: Hi again Got a bit sidetracked ... here is your original code :) Thanks, I managed to make it work for me similarly to that. Now, a different problem, I already have array variable with a object. Is there a way to make a function return a reference to that object in a variable passed by reference to a function? Regards, Manuel Lemos -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Unable to return object references from functions
Hi What is the scope of the array that holds the object ? Maybe a bit of code to show what you are after :) Tom At 03:37 PM 17/12/01, Manuel Lemos wrote: Hello, Tom Rogers wrote: Hi again Got a bit sidetracked ... here is your original code :) Thanks, I managed to make it work for me similarly to that. Now, a different problem, I already have array variable with a object. Is there a way to make a function return a reference to that object in a variable passed by reference to a function? Regards, Manuel Lemos -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Unable to return object references from functions
Hello, Tom Rogers wrote: Hi What is the scope of the array that holds the object ? global Maybe a bit of code to show what you are after :) It is to implement another function that will return a reference (not a copy) of a object stored in a global array passing the index of the array. It would be like this, except that this code does not work as I need: $objects=array(); Function CreateObject($index) { global $objects; $index=count($objects); $objects[$index]=new my_class; } Function GetObject($index,$object) { global $objects; $object= $objects[$index]; } CreateObject($index); GetObject($index,$my_object); Regards, Manuel Lemos Tom At 03:37 PM 17/12/01, Manuel Lemos wrote: Hello, Tom Rogers wrote: Hi again Got a bit sidetracked ... here is your original code :) Thanks, I managed to make it work for me similarly to that. Now, a different problem, I already have array variable with a object. Is there a way to make a function return a reference to that object in a variable passed by reference to a function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Unable to return object references from functions
Hi Is this doing what you want, seems you have to use an array to create the ref (just getting a handle on objects :) ? class test_class { var $dummy=nothing; }; Function assigning($returned,$copy,$object) { global $success; $object-dummy=original; $success=1; $copy=$object; $copy-dummy=copy; $returned[] = $object; var_dump(In the function,$success,$returned[0],$copy,$object); return $object; } $object = assigning($returned,$copy,new test_class); echo brbr; var_dump(Out the function,$success,$returned[0],$copy,$object); ? At 03:06 PM 15/12/01, you wrote: Hello, I am trying to return a reference from an object created inside a function and at the same time have the object stored in a global variable. It seems that when I try doing it by assigning the object reference to a function argument that is passed by reference, nothing is returned in that variable despite inside the function the argument variable seems to have the right value. Is this a PHP bug or this is not the right way to do it? Try the example below. Manuel Lemos ? class test_class { var $dummy=nothing; }; Function not_assigning($not_returned,$copy) { global $object; $object=new test_class; $object-dummy=original; $success=1; $not_returned= $object; $copy=$object; $copy-dummy=copy; var_dump(In the function,$success,$not_returned,$copy,$object); return $success; } $success=not_assigning($not_returned,$copy); var_dump(Out the function,$success,$not_returned,$copy,$object); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Unable to return object references from functions
Hi again Got a bit sidetracked ... here is your original code :) class test_class2 { var $dummy=nothing; }; Function not_assigning($not_returned,$copy) { global $object; $object = new test_class; $object-dummy=original; $success=1; $not_returned[] = $object; $copy=$object; $copy-dummy=copy; var_dump(In the function,$success,$not_returned[0],$copy,$object); return $success; } $success = not_assigning($not_returned,$copy); echo brbr; var_dump(Out the function,$success,$not_returned[0],$copy,$object); ? At 02:15 PM 16/12/01, Tom Rogers wrote: Hi Is this doing what you want, seems you have to use an array to create the ref (just getting a handle on objects :) ? class test_class { var $dummy=nothing; }; Function assigning($returned,$copy,$object) { global $success; $object-dummy=original; $success=1; $copy=$object; $copy-dummy=copy; $returned[] = $object; var_dump(In the function,$success,$returned[0],$copy,$object); return $object; } $object = assigning($returned,$copy,new test_class); echo brbr; var_dump(Out the function,$success,$returned[0],$copy,$object); ? At 03:06 PM 15/12/01, you wrote: Hello, I am trying to return a reference from an object created inside a function and at the same time have the object stored in a global variable. It seems that when I try doing it by assigning the object reference to a function argument that is passed by reference, nothing is returned in that variable despite inside the function the argument variable seems to have the right value. Is this a PHP bug or this is not the right way to do it? Try the example below. Manuel Lemos ? class test_class { var $dummy=nothing; }; Function not_assigning($not_returned,$copy) { global $object; $object=new test_class; $object-dummy=original; $success=1; $not_returned= $object; $copy=$object; $copy-dummy=copy; var_dump(In the function,$success,$not_returned,$copy,$object); return $success; } $success=not_assigning($not_returned,$copy); var_dump(Out the function,$success,$not_returned,$copy,$object); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]