php 5.3.2 not throwing exceptions
I'm attempting to throw an exception using php 5.3.2 and it is giving me the following error:
Parse error: syntax error, unexpected T_THROW
I am attempting to throw an exception the following way:
throw new Exception('Property ' . $name . ' doesn\'t exist in class Index', '');
Edit: I also tried
throw new Exception('Property ' . $name . ' doesn\'t exist in class开发者_如何转开发 Index');
it didn't change the error I was getting.
The complete method:
public function __get($name)
{
if(property_exists($this, $name)
throw new Exception('Property ' . $name . ' doesn\'t exist in class Index');
return $this->$name;
}
check your php code for bloopers, sometimes i miss off a ';' which can cause errors.
also try writing the if statement formally, adding in brackets. i know it shouldn't make any odds but who knows with programming!
You are missing the closing parenthesis of your if() line and so PHP sees this
if(property_exists($this, $name) throw new Exception(...);
which is not valid syntax. Place a ) at the end of your if() line:
if(property_exists($this, $name))
Edit: I hate when I miss the replies below an answer. :(
精彩评论