doudao7511 2014-01-06 11:30
浏览 49
已采纳

在声明php时初始化变量时出错

when I try to initialize variable while declaring I get syntax error: unexpected T_VARIABLE. Here is my code:

class TagProduct extends CI_Controller {

// num of records per page
private $limit = 10;
private $CurrentDate;
private $LoginID=$this->session->userdata('UserID');
private $Errmsg=array(
                        'TagErr'=>'',
                        'ProductErr'=>'',
                    );

function __construct()
{
    parent::__construct();
  • 写回答

1条回答 默认 最新

  • drlnsli18864734 2014-01-06 11:35
    关注

    Properties must be initialized by constants in PHP:

    Use Structure like this:

    class TagProduct extends CI_Controller {
    
    private $limit;
    
        function __construct() {
            $this->limit = 10;
        }
    }
    

    Check in php.net

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?