PHP 5.0 passes objects by reference automatically?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Wes Bailey
    Guest replied
    Re: PHP 5.0 passes objects by reference automatically?

    Unless I am missing something in this code snippet, there isn't any
    language that would ever print back 7 since the method Foo is never
    invoked. This isn't a property of the language, instead its the
    behaviour of you code.

    Wes Bailey
    [color=blue]
    >Toni Schornboeck <toni@schornboe k.net> wrote in message
    > news:<3f04afef$ 0$21620$91cee78 3@newsreader01. highway.telekom .at>...
    > lawrence wrote:[color=green]
    > > Do I understand correctly that in PHP 5.0 objects will be passed by
    > > reference (by handle, they say) automatically, not as a copy, as
    > > happens with most PHP variables?[/color]
    >
    > That's right.
    > It will be like in Java - variables are just references (or like Zend
    > call them: handles) to objects.
    > This will be a big performance improvement!
    >
    > I haven't had time to test PHP5, so could someone test this code:
    >
    >
    > class Test
    > {
    > public $i;
    > function __construct($i)
    > {
    > $this->i=$i;
    > }
    > }
    >
    > function foo($obj)
    > {
    > $obj=new Test(7);
    > }
    >
    > $obj=new Test(5);
    > echo $obj->i;
    >
    > is it like java where it would print 5? or does PHP5 is smarter and
    > prints 7?[/color]

    Leave a comment:


  • Zeek
    Guest replied
    Re: PHP 5.0 passes objects by reference automatically?

    "Toni Schornboeck" <toni@schornboe k.net> wrote in message
    news:3f04afef$0 $21620$91cee783 @newsreader01.h ighway.telekom. at...[color=blue]
    > lawrence wrote:[/color]
    [snip snip][color=blue]
    > is it like java where it would print 5? or does PHP5 is smarter and
    > prints 7?[/color]

    5 ... (apache2+php5b1 )


    Leave a comment:


  • Manuel Lemos
    Guest replied
    Re: PHP 5.0 passes objects by reference automatically?

    Hello,

    On 07/03/2003 07:33 PM, Toni Schornboeck wrote:[color=blue]
    > lawrence wrote:
    >[color=green]
    >> Do I understand correctly that in PHP 5.0 objects will be passed by
    >> reference (by handle, they say) automatically, not as a copy, as
    >> happens with most PHP variables?[/color]
    >
    >
    > That's right.
    > It will be like in Java - variables are just references (or like Zend
    > call them: handles) to objects.
    > This will be a big performance improvement![/color]

    It is not a real performance improvement. You could always do that in
    PHP 4, except that you needed to use the & operator to avoid copying
    like this:

    $my_object = &new my_class;


    --

    Regards,
    Manuel Lemos

    Free ready to use OOP components written in PHP
    http://www.phpclasses.org/

    Leave a comment:


  • lawrence
    Guest started a topic PHP 5.0 passes objects by reference automatically?

    PHP 5.0 passes objects by reference automatically?

    Do I understand correctly that in PHP 5.0 objects will be passed by
    reference (by handle, they say) automatically, not as a copy, as
    happens with most PHP variables?
Working...