Monika Yadav
Monika Yadav

Reputation: 381

Error when initializing variable at the time of declaration 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();

Upvotes: 0

Views: 51

Answers (1)

Nisarg
Nisarg

Reputation: 3252

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

Upvotes: 2

Related Questions