简体   繁体   中英

Error trying to use static var inside an array in another class var

Besides of talk a lot of not useful things, there goes my code:

1 public static $_INT = 'INTEGER';
2 protected $_name = 'projetos';
3 protected $_primary = 'id';
4 protected $_fields = Array (
    Array ('id', self::$_INT)
);

I'm having an error on line 4.

self::$_INT is an expression, you cannot use an expression in the declaration of a property in a class, you can only use static values.

You will have to initialise $_fields in the constructor if you want to do this.

Like

class MyClass {

  public static $_INT = 'INTEGER';
  protected $_name = 'projetos';
  protected $_primary = 'id';
  protected $_fields;

  public function __construct() {
    $this->fields = Array (
      Array ('id', self::$_INT)
    );
  }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM