Instantiating an object does have some extra overhead that the static call bypasses. How much overhead depends on the complexity of the object, I would predict that it's mainly in its constructor and any parent constructors. I can't speak to differences in PHP4/PHP5 in this specific regard, but would make a wild guess that they would not be THAT different in performance if the thing works in both. On Sun, April 30, 2006 9:12 am, Edward Vermillion wrote: > I'm still trying to get my head around all the OOP stuff and was > wondering if there is any basic difference between calling a static > function as opposed to creating an object, in situations where both > methods will do the same thing for you. Is there any overhead to > creating an object from a class that might impact time/memory > consumption(efficiency), or does PHP treat these two methods the > same? I'm currently working with PHP4 but am also curious as to how > it works in PHP5. > > I.E.: > > <pseudoCode> > class Foo { > > var $_vars = array(); > > function &setVar1($var) { > static $localVars = array(); > if (!empty($localVars[$var])) { > return $localVars[$var]; > } else { > $localVars[$var] =& new $var(); > return $localVars[$var]; > } > } > > function &setVar2($var) { > if (!empty($this->_vars[$var])) { > return $this->_vars[$var]; > } else { > $this->_vars[$var] =& new $var(); > return $this->_vars[$var]; > } > } > } > > $result1 =& Foo::setVar1('something'); > > $bar = new Foo(); > $result2 =& $bar->setVar2('something'); > </pseudoCode> > > Right now I'm working on an object controller type of class, but I > can see where I might run into this situation in other areas where > storing a value in a static function variable or a class variable > would accomplish much the same thing as far as the calling code is > concerned. > > Any thoughts? > > Ed > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php