Reply to Performance question - passing data between objects (PHP4-style OOP)

Your name:

Reply:


Posted by Markus Ernst on 11/09/06 10:48

Hello

A class that composes the output of shop-related data gets some info
from the main shop class. Now I wonder whether it is faster to store the
info in the output class or get it from the main class whenever it is
needed:

class shop_main {
var $prices = null;
function &get_prices() {
if (is_null($this->prices)) {
$this->prices =& $this->db->getCol('SELECT id FROM shop_prices');
if (!is_array($this->prices)) $this->prices = array();
}
return $this->prices;
}
}

// case 1: store info in class
class shop_output {
var $prices = null;
var $main_shop_obj;
function do_something($product_id) {
if (is_null($this->prices)) {
// assume that main shop object is already set
$this->prices =& $this->main_shop_obj->get_prices();
}
foreach ($this->prices as $price_id) {
// do something...
}
}
}

// case 2: get info each time it is needed
class shop_output {
var $main_shop_obj;
function do_something($product_id) {
// assume that main shop object is already set
foreach ($this->main_shop_obj->get_prices() as $price_id) {
// do something...
}
}
}

BTW I also wonder whether it is appropriate to pass the prices by
reference here - I assume it is, but in an older thread on performance
Chung Leung stated that passing by reference can decrease performance in
some cases.

Thanks for a comment!
Markus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация