Returning References

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

    Returning References

    according to the php manual, it said:

    Do not use return-by-reference to increase performance, the engine is
    smart enough to optimize this on its own.

    I doubt if this only apply to the PHP5 engine, while if I am using
    PHP4, performance is a factor to continue to use return by refercnece?

  • Jerry Stuckle

    #2
    Re: Returning References

    howa wrote:
    according to the php manual, it said:
    >
    Do not use return-by-reference to increase performance, the engine is
    smart enough to optimize this on its own.
    >
    I doubt if this only apply to the PHP5 engine, while if I am using
    PHP4, performance is a factor to continue to use return by refercnece?
    >
    Even in PHP 4 you won't find a significant difference (if any) between
    return by reference and return by value.

    If you're having performance problems, I'd suggest doing some debugging
    to figure out where the problems really are.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • alo.and@gmail.com

      #3
      Re: Returning References

      according to the php manual, it said:
      >
      Do not use return-by-reference to increase performance, the engine is
      smart enough to optimize this on its own.
      >
      I doubt if this only apply to the PHP5 engine, while if I am using
      PHP4, performance is a factor to continue to use return by refercnece?
      No, return by reference will not increase performance even in PHP4,
      unless you're using a really huge variable with MBs of data, that is
      not the common case.

      Using references without a technical reason to do that (when you really
      need a reference to be returned) wil only cause unecessary annoyances
      to the coders.

      Remember to mantain your code as simple as possible while this practice
      will not cause any perceptible performance or other issues.

      Also, its important to say that normally the principal bottleneck in a
      common PHP application is the Database, that eventually need a fine
      tuning. PHP performance is easily solved using an opcode cache
      soluction, like APC, that mantain your scripts compiled in memory,
      elimitating the compile time when each access is requested to the
      webserver.

      Best regards,
      Alonso

      Comment

      • Andy Hassall

        #4
        Re: Returning References

        On 31 Dec 2006 20:04:10 -0800, "howa" <howachen@gmail .comwrote:
        >according to the php manual, it said:
        >
        >Do not use return-by-reference to increase performance, the engine is
        >smart enough to optimize this on its own.
        >
        >I doubt if this only apply to the PHP5 engine, while if I am using
        >PHP4, performance is a factor to continue to use return by refercnece?
        This does apply to PHP4. zend.com seem to have rearranged their site which has
        made an article on this disappear but it's still available from archive.org:

        PHP, Unix, Linux, Apache, server software, scripting languages, free, downloads, developers, dynamic web pages, e-commerce, optimizer, compiler, open source, mySQL, ASP, Zend Engine, performance, tutorials, manuals, documentation, knowledge base, products, articles, resources, tips, code gallery, script archive, programming, business, technology, HTML


        From PHP4, assignments are always done by reference initially, and the work of
        doing a copy is only done when the new variable is _modified_. Using references
        (excessively) actually ends up doing slightly more work. When you return a
        large string value from a function without return-by-reference then it doesn't
        start making copies of it - the ref-counting mechanism is supposed to be "smart
        enough" to avoid this.

        The exception is for objects where you do want (almost) every assignment to be
        a reference in PHP4 - but not in PHP5.

        --
        Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        Working...