尝试在另一个类var中使用数组内部的静态var时出错

时间:2012-07-16 12:38:27

标签: php

除了谈论很多没用的东西之外,还有我的代码:

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

我在第4行遇到错误。

1 个答案:

答案 0 :(得分:6)

self::$_INT是一个表达式,你不能在类的属性声明中使用表达式,你只能使用静态值。

如果你想这样做,你必须在构造函数中初始化$_fields

喜欢

class MyClass {

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

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

}