Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

PHP error


Reply

2 Posts   532 Views

Avatar
servalman

22 July 2010 at 10:59pm Community Member, 211 Posts

Hi

Can someone tells me what's wrong with this :

public   function hasPress()
{
if ($this->PressRelease == '') then return false;
else return true;
}

I'm getting an unexpected T_RETURN but I don't know what to correct all the ; seems to be in the right place

thanks

Avatar
UncleCheese

24 July 2010 at 6:56am (Last edited: 24 July 2010 6:57am), 4085 Posts

There is no "then" in PHP syntax.

Also, your function is unnecessarily complicated. Here it is, revised:

public function hasPress()
{
return $this->PressRelease != '';
}

In all honesty, you can probably just say,

return $this->PressRelease.

If $this->PressRelease is null or empty, that is evaluated as false in PHP.

That function is useless on a template, btw, because <% if PressRelease %> does the same thing.