PHP 5.0 passes objects by reference automatically?

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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?
    lawrence Guest

  2. Similar Questions and Discussions

    1. I need reference for the objects and methods
      I need reference for the objects and methods that comm server support. can smb. help? I have good skills in ActionScript but I'm new to the comm....
    2. Web reference/Proxy class problems with custom objects
      I have built a webservice which consumes and returns a custom object/class which was generated using XSD.exe from an XML schema. When WSDL.exe...
    3. [PHP] Passing objects as a reference and extracting the indexof an associative array.
      Webmaster wrote: There is no "assignVars" method within Smarty. Are you using something else overtop of it? You can assign the whole array...
    4. Help: cross-reference overflow between 2 different images/objects
      Hello! I got a question this time. It should be a question in general. I´m lookin for a method that might be inside a plugin or filter. It would...
    5. parsing log in multiple passes
      I have output from a CLI that I am parsing into a data structure (hash) to be used as input to another program which reads the hash. The CLI always...
  3. #2

    Default Re: PHP 5.0 passes objects by reference automatically?

    Hello,

    On 07/03/2003 07:33 PM, Toni Schornboeck wrote:
    > lawrence wrote:
    >
    >> 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?
    >
    >
    > 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!
    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
    [url]http://www.phpclasses.org/[/url]

    Manuel Lemos Guest

  4. #3

    Default Re: PHP 5.0 passes objects by reference automatically?

    "Toni Schornboeck" <toni@schornboek.net> wrote in message
    news:3f04afef$0$21620$91cee783@newsreader01.highwa y.telekom.at...
    > lawrence wrote:
    [snip snip]
    > is it like java where it would print 5? or does PHP5 is smarter and
    > prints 7?
    5 ... (apache2+php5b1)


    Zeek Guest

  5. #4

    Default 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
    >Toni Schornboeck <toni@schornboek.net> wrote in message
    > news:<3f04afef$0$21620$91cee783@newsreader01.highw ay.telekom.at>...
    > lawrence wrote:
    > > 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?
    >
    > 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?
    Wes Bailey Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139