Re: Unable to return object references from functions
| From: | John Lim | Date: | Sat, 15 Dec 2001 14:48:12 +0000 |
| Subject: | Re: Unable to return object references from functions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-77819@lists.php.net to get a copy of this message | ||
Hi Yasuo,
I seem to remember having similar problems understanding objects and
references
also and you guided me here. Manuel is a good programmer and if he also has
problems, I'm a bit worried for novices. Objects and references are not
intuitive :(
Regards, John
Yasuo Ohgaki <yasuo_ohgaki@yahoo.com> wrote in message
news:3C1AF302.1070204@yahoo.com...
> Manuel Lemos 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?
>
>
> No this is not a bug, but issue.
>
> Please ask this kind of question only to php-general.
> Thank you.
>
> PS: Read manaul sections (Object and Reference.
> It's explained ;)
>
> --
> Yasuo Ohgaki
>
> >
> > 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);
> >
> > ?>
> >
>
>
>
> --
> Yasuo Ohgaki
>