[development] passing data is free
Earl Miles
merlin at logrus.com
Tue Oct 9 05:44:21 UTC 2007
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.
More information about the development
mailing list