SchweppesAle Posted January 25, 2010 Share Posted January 25, 2010 Was wonder when is it appropriate to use static functions? I have an example below, both accomplish the same task, however one requires that an instance of the factory class be created before it can be used. <?php require_once('testObject.php'); class factory { private $_testObject; function __construct() { } function getTestObject() { return $this->_testObject = new testObject(); } static function getStaticObject() { return new testObject(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189684-static-functions-vs-initialized-object-functions/ Share on other sites More sharing options...
KevinM1 Posted January 25, 2010 Share Posted January 25, 2010 Well, the difference stems from the decision you need to make on whether or not you need an instance of a class in order to do the job. Factories are often abstract with static methods because it's often unnecessary to have to deal with a concrete object for the factory to do its job. They return concrete product objects, however. Quote Link to comment https://forums.phpfreaks.com/topic/189684-static-functions-vs-initialized-object-functions/#findComment-1001103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.