Why do I get this error when trying to set up a class variable

Posted by Jennifer on Stack Overflow See other posts from Stack Overflow or by Jennifer
Published on 2010-03-22T22:50:37Z Indexed on 2010/03/22 23:01 UTC
Read the original article Hit count: 314

Filed under:
|

I'm new to PHP so maybe I am overlooking something here but the following:

class someClass {

    var $id = $_GET['id'];

    function sayHello() {

        echo "Hello";

    }

}

gives the following error:

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\files\classes.php on line 13

If instead of $_GET['id'] I set the variable $id to a string, everything is fine though.

© Stack Overflow or respective owner

Related posts about php

Related posts about syntax-error