CodeIgniter Forums
Private vairable not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Private vairable not working (/showthread.php?tid=65801)



Private vairable not working - wolfgang1983 - 07-26-2016

On the top above my __construct() area in my library I have a variable called $set_the_time_for_cookie_to_expire because the time() has brackets it is throwing error


Code:
A PHP Error was encountered

Severity: Parsing Error

Message: syntax error, unexpected '(', expecting ',' or ';'

Filename: libraries/Customer.php

Line Number: 6

Backtrace:


Is there any way to be able to use php time() like what I am after?


PHP Code:
private $customer_id;
private 
$set_the_time_for_cookie_to_expire time() + 20 60;
 
   
public function __construct() {
 
  $this->CI = &get_instance();
 
  $this->CI->load->library('session');

 
  if (!$this->CI->session->userdata('is_logged_in')) {
 
     $this->autologin();
 
  }





RE: Private vairable not working - InsiteFX - 07-26-2016

Create a set and get method to set and get the cookie expire time.


RE: Private vairable not working - Wouter60 - 07-26-2016

Assign the value in the __construct method.

PHP Code:
private $set_the_time_for_cookie_to_expire;

public function 
__construct() {
   
$this->set_the_time_for_cookie_to_expire time() + 20 60;




RE: Private vairable not working - InsiteFX - 07-26-2016

Yep that will work also but I would still create the set and get methods so that if you ever want to change the expiration time you can.