Search code examples
phpexceptionphp-5.3

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;
    }

Solution

  • 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!