Jump to:

23013 Posts in 11872 Topics by 2830 members

General Questions

SilverStripe Forums » General Questions » PHP error

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

Page: 1
Go to End
Author Topic: 493 Views
  • servalman
    Avatar
    Community Member
    211 Posts

    PHP error Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: PHP error Link to this post

    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.

    493 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.