0

Possible Duplicate:
declare property as object?

class core
{
 public $dbh = new PDO("mysql:dbname=newdbnaem;host=1.1.1.1:1111", "owner", "passwordlulz");
 function superman() {}
}

gives me a syntax error on the closing tag of the function.

Community
  • 1
  • 1
Uğur Gümüşhan
  • 2,455
  • 4
  • 34
  • 62

1 Answers1

4

Only constant values can be used as initializers for class properties. Do it in the constructor:

class core {

    public $dbh = null;

    public function __construct() {
        $this->dbh = new PDO("mysql:dbname=newdbnaem;host=1.1.1.1:1111", "owner", "passwordlulz");
    }

}

This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

http://www.php.net/manual/en/language.oop5.properties.php

deceze
  • 510,633
  • 85
  • 743
  • 889