FAQ
To quote one of the most experienced Drupal developer:

"The menu item array includes a copy of the whole node for example on
node pages. Well, obviously that might be useful for some help stuff,
but most of the time it is not required, so why pass on this data in
all cases?"

Why not? Passing data around is basically free. You are not copying
the data, you are creating a reference, deep copy only happens if you
modify the passed in argument (PHP5 only deep copies an object if you
instruct it with clone()). So do not hesitate to pass around as many
data as you want.

Not for the first time I urge fellow developers to read
http://web.archive.org/web/20061205052540rn_1/www.zend.com/zend/art/ref-count.php
this excellent article which is so old that you need archive.org to
read it but is still valid.

For deeper understanding read
http://book.chinaunix.net/special/ebook/php/Programming.PHP_2/0596006810/progphp2-CHP-14.html

Search Discussions

  • Sean Robertson at Oct 8, 2007 at 10:09 pm

    Why not? Passing data around is basically free. You are not copying
    the data, you are creating a reference, deep copy only happens if you
    modify the passed in argument (PHP5 only deep copies an object if you
    instruct it with clone()). So do not hesitate to pass around as many
    data as you want.
    How much difference is there in this between PHP4 and PHP5?
  • Larry Garfield at Oct 9, 2007 at 2:33 am

    On Monday 08 October 2007, Sean Robertson wrote:
    Why not? Passing data around is basically free. You are not copying
    the data, you are creating a reference, deep copy only happens if you
    modify the passed in argument (PHP5 only deep copies an object if you
    instruct it with clone()). So do not hesitate to pass around as many
    data as you want.
    How much difference is there in this between PHP4 and PHP5?
    This much:
    http://www.php.net/manual/en/migration5.php

    The change in the way objects are passed is the only BC break that is not
    trivial to handle if you take care to do so, and Drupal has taken very good
    care to do so.

    --
    Larry Garfield AIM: LOLG42
    larry at garfieldtech.com ICQ: 6817012

    "If nature has made any one thing less susceptible than all others of
    exclusive property, it is the action of the thinking power called an idea,
    which an individual may exclusively possess as long as he keeps it to
    himself; but the moment it is divulged, it forces itself into the possession
    of every one, and the receiver cannot dispossess himself of it." -- Thomas
    Jefferson
  • Earl Miles at Oct 9, 2007 at 5:44 am

    Karoly Negyesi wrote:
    To quote one of the most experienced Drupal developer:

    "The menu item array includes a copy of the whole node for example on
    node pages. Well, obviously that might be useful for some help stuff,
    but most of the time it is not required, so why pass on this data in
    all cases?"

    Why not? Passing data around is basically free. You are not copying
    the data, you are creating a reference, deep copy only happens if you
    modify the passed in argument (PHP5 only deep copies an object if you
    instruct it with clone()). So do not hesitate to pass around as many
    data as you want.

    Not for the first time I urge fellow developers to read
    http://web.archive.org/web/20061205052540rn_1/www.zend.com/zend/art/ref-count.php
    this excellent article which is so old that you need archive.org to
    read it but is still valid.

    For deeper understanding read
    http://book.chinaunix.net/special/ebook/php/Programming.PHP_2/0596006810/progphp2-CHP-14.html
    More importantly, this is one of the biggest reasons that people might
    choose an OO paradigm over a procedural paradigm. With an object
    oriented model, data tends to stick together; in the procedural model,
    you get issues like this one, where you find yourself passing data you
    may or may not need.
  • Doug Green at Oct 9, 2007 at 9:17 am

    Earl Miles wrote:
    Karoly Negyesi wrote:
    Why not? Passing data around is basically free. You are not copying
    the data, you are creating a reference, deep copy only happens if you
    modify the passed in argument (PHP5 only deep copies an object if you
    instruct it with clone()). So do not hesitate to pass around as many
    data as you want.
    More importantly, this is one of the biggest reasons that people might
    choose an OO paradigm over a procedural paradigm. With an object
    oriented model, data tends to stick together; in the procedural model,
    you get issues like this one, where you find yourself passing data you
    may or may not need.
    I have no desire to start up the OO debate. So I'll make one statement
    then stop.

    With an OO language, data might be passed around, it is just handled by
    the language. For example, in many (some/all?) C++ compilers, it is the
    first argument on the stack, and the compiler/language simply handles
    dereferencing it.

    You can simulate some aspects of OO code without an OO language. What
    you can't easily do is overloading. But data encapsulation and function
    naming can be handled with good programming and naming conventions.

    I said I wouldn't start up the debate, so I'll leave it there. BTW, I
    probably started using C++ within 1-2 years of it's release, so I like
    OO languages, and have some experience with them.

    --
    Doug Green
    douggreen at douggreenconsulting.com
    904-583-3342

    Bringing Ideas to Life with Software Artistry and Invention...
  • Earnie Boyd at Oct 9, 2007 at 12:26 pm

    Quoting Earl Miles <merlin at logrus.com>:

    Karoly Negyesi wrote:
    To quote one of the most experienced Drupal developer:

    "The menu item array includes a copy of the whole node for example on
    node pages. Well, obviously that might be useful for some help stuff,
    but most of the time it is not required, so why pass on this data in
    all cases?"

    Why not? Passing data around is basically free. You are not copying
    the data, you are creating a reference, deep copy only happens if you
    modify the passed in argument (PHP5 only deep copies an object if you
    instruct it with clone()). So do not hesitate to pass around as many
    data as you want.

    Not for the first time I urge fellow developers to read
    http://web.archive.org/web/20061205052540rn_1/www.zend.com/zend/art/ref-count.php
    this excellent article which is so old that you need archive.org to
    read it but is still valid.

    For deeper understanding read
    http://book.chinaunix.net/special/ebook/php/Programming.PHP_2/0596006810/progphp2-CHP-14.html
    More importantly, this is one of the biggest reasons that people
    might choose an OO paradigm over a procedural paradigm. With an
    object oriented model, data tends to stick together; in the
    procedural model, you get issues like this one, where you find
    yourself passing data you may or may not need.
    I think Karoly's point is that with improvements of PHP 5 we can count
    on the data stack only being copied if there is a change to the data.
    This has nothing to do with OO vs procedural. It has to do with the
    operation of the script engine upon the data structures and the passing
    of the data to the functions, be it in OO or procedural.

    Earnie -- http://for-my-kids.com/
    -- http://give-me-an-offer.com/
  • Karoly Negyesi at Oct 10, 2007 at 3:39 am

    I think Karoly's point is that with improvements of PHP 5 we can count
    on the data stack only being copied if there is a change to the data.
    I think you have not read my letter or any of the articles I linked to and even failed to check their date, the Zend article is from 2000. That's PHP 4 you wanted to say not PHP 5.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdevelopment @
categoriesdrupal
postedOct 8, '07 at 10:06p
activeOct 10, '07 at 3:39a
posts7
users6
websitedrupal.org
irc#drupal

People

Translate

site design / logo © 2022 Grokbase