在php类定义中导致解析错误的变量

时间:2014-04-24 21:45:28

标签: php variables

为什么会导致解析错误?如果我换掉整数变量,它可以正常工作。我只能假设解析器无法解析字符串中的变量,但我不明白为什么。

    private $last_fetch=array(); // the content of the last database query
    private $last_thread_id=0; // the id of the last thread of the previous fetch
    private $threads_max_fetch=20; // max number of threads to fetch from the database

    private $q="SELECT DISTINCT mt.* 
        FROM message_thread mt
        INNER JOIN message m
        ON mt.thread_id=m.thread.id
        WHERE mt.thread_id < $this->last_thread_id
        ORDER BY m.message_datetime
        LIMIT $this->threads_max_fetch";

1 个答案:

答案 0 :(得分:0)

请参阅manual关于类属性声明:

  

这个声明可能包括初始化,但是这个   初始化必须是一个常量值 - 也就是说,它必须能够   在编译时进行评估,不得依赖于运行时   信息以便进行评估。

所以你根本不能在声明/初始化中使用变量。