If a static method returns an object .. can I in one line get one of the objects attributes? Something like this but in a single line :
$obj = Parser::GetFirstItem();
$strTitle = $obj->Title;
If a static method returns an object .. can I in one line get one of the objects attributes? Something like this but in a single line :
$obj = Parser::GetFirstItem();
$strTitle = $obj->Title;
Sure. Just try it out:
$strTitle = Parser::GetFirstItem()->Title;
Not entirely sure when this was introduced. 5? 5.1? 5.2? Will have to check.
Update: Seems to have been a PHP 5 feature from the start.
Have you actually tried it?
$strTitle = Parser::GetFirstItem()->Title;
That should work, provided you're using PHP5 and not still stuck on PHP4.
Your GetFirstItem
method should returns an object. Only virtual (not static methods) can do this:
return $this;