I’m trying to assign a value to a static class property when defining it:
namespace Base;
abstract class Skeleton {
protected static $entityManager = \Zend_Registry::get("EntityManager");
...
}
When I try to execute this code I get this error:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /var/www/
somewhere/application/models/Base/Skeleton.php on line 6
If I just assign a simple string value to it:
protected static $entityManager = "string";
Everyting is fine. Am I doing something PHP can’t handle? If so, how to solve this?
You can’t put code that needs executing as a class variable, static or not.
Think about it, at which point does
Zend_Registry::get("EntityManager")get executed, it can’t be executed when the class is created because you have set it asstatic.Even if it was not static, when does
Zend_Registry::get("EntityManager")get run? When the object is instantiated or once? It needs to be put in a function inside the class.