Lee
Lee

Reputation: 3969

Expecting T_STRING?

Here's a very bare class with one static method. I cannot for the life of me work out why it's throwing the error:

Parse error: parse error, expecting `T_STRING' in C:...\error.php on line 7

This is the code:

<?php

    # Error class to handle errors
    class Error
    {
        # Function to throw an error - which redirects with error msg
        public static function Throw($id, $dest) // line 7
        {
            System::Redirect($dest."&e=$id");
            exit;
        }
    }

?>

Upvotes: 0

Views: 174

Answers (3)

Chad
Chad

Reputation: 364

Throw is a reserved word; you won't get that error if you call it, for instance, myThrow.

Another thing to watch out for is that if $dest has no parameters already being passed (eg just foo.com instead of foo.com?param=1), then appending '&e=id' to it will result in 'foo.com&e=id' which will break.

Upvotes: 0

Marc B
Marc B

Reputation: 360632

Throw is a reserved word in php.

Upvotes: 2

John Cartwright
John Cartwright

Reputation: 5084

Throw is a reserved keyword, therefore you cannot use it as a method name.

See http://www.php.net/manual/en/reserved.keywords.php

Upvotes: 4

Related Questions