edave
edave

Reputation: 188

php access class by string

The following code works fine on my localhost and my first hoster, but not at my new hoster.

static function setup ($childModel) {
  query::create()
   ->name($childModel::$tableName)
   ->mayExist()
   ->row($childModel::$struct)
   ->key($childModel::$index)
   ->run();
}

$childModel contains a string with the name of a class. Worked fine so far, but the new server says:

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /***/model.php on line 71

(line 71 is line 3 of the code above)

I know this means that he dont like the ::, but why do none of my other servers complain here? And what can I do about this?

UPDATE: It works now. It seems like it just took time for the server to switch to the new php version. Sorry everybody! (How do I close this thread?)

Upvotes: 0

Views: 101

Answers (1)

gen_Eric
gen_Eric

Reputation: 227280

The $childModel::$tableName syntax (using variables as class names) only works in PHP 5.3+.

It seems like your new host is using an older version of PHP.

Upvotes: 1

Related Questions