Class Confusion: instantiation objects within a constant
const DEFAULT_ENGINE_LIST = array(
'google' => new GoogleSearch(),
'yahoo' => new YahooSearch(),
'flickr' => new FlickrSearch(),
'blip' => new BlipSearch(),
'jamendo' => new JamendoSearch(),
'spin' => new SpinSearch()
throws this error:
so it looks like maybe i can't instantiate objects in a constant?
Parse error: syntax error, unexpected T_NEW [ . . . ]
i really just want to set a default value for this "var" $_engineList, which will hold an array of these engine objects. the idea is to have them all in one place so that more can be added later. by making as few edits as possible. perhaps i should re-think my approach?
Not only can you not use new in that context, but array() will result in a run-time error. Off the top of my head without knowing all the details, I'd guess you'll have to settle for a class variable that is an array of objects, and you'll need to populate it via the constructor.
public /* or private? */ $defaultEngineList = array();
public function __construct()
$this->defaultEngineList['google'] = new googleSearch();
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)