Page 1 of 1
Undefined Variable: expire
Posted: Fri Jun 17, 2016 3:29 am
by renegadomty
PHP Notice: Undefined variable: expire in C:\inetpub\wwwroot\oc\system\library\template.php
Hi guys, how are you?
First at all, Sorry for my English , but im gonna try to write the best of me.
Well.
im new in PHP, but, with some tutorials im turn on the MySql Server and PHP extensión in my IIS 7.5
Well, the problema is this
When im trying to open the OpenCart Installation, this throw me an exception: "PHP Notice: Undefined variable: expire in C:\inetpub\wwwroot\oc\system\library\template.php on line 9 ".
when i put this into a GoDaddy, this Works fine!!, but in my local machin this fail..
Can you help me please
im using:
PHP 7
Windows 7 profesional
MySql 5.7
Best regards.
Re: Undefined Variable: expire
Posted: Wed Oct 19, 2016 7:41 am
by doktorek
I had that error no matter what I did. Even when installing a new version from scratch. Downgrade your php version. I had it at 7.1 when I had the error. Now I set in the cpanel to version 7.0 and it is gone.
So whenever you get this error - downgrade PHP version
Re: Undefined Variable: expire
Posted: Tue Apr 04, 2017 2:00 am
by damodaranudas
doktorek wrote: ↑Wed Oct 19, 2016 7:41 am
I had that error no matter what I did. Even when installing a new version from scratch. Downgrade your php version. I had it at 7.1 when I had the error. Now I set in the cpanel to version 7.0 and it is gone.
So whenever you get this error - downgrade PHP version
I had the same issue, downgrading to PHP 7.0 fixed it as well

Re: Undefined Variable: expire
Posted: Thu Apr 20, 2017 4:39 pm
by burley
I'm having the same issue! Also on a clean install, on a local server.
But surely, downgrading the PHP version could not be the final and best solution?!
Re: Undefined Variable: expire
Posted: Thu Apr 20, 2017 5:07 pm
by artcore
Came across it a few days ago as well after updating to php7.1
I did a quick fix:
if(!isset($expire)){$expire=86400;}
$this->adaptor = new $class($expire);
Didn't check what expire means in context or what called it, just added a default value of 1 day as it sounded like a cache expiration time.
Re: Undefined Variable: expire
Posted: Thu Apr 20, 2017 5:17 pm
by burley
Will defenitly give that a try!
Thanks!!
Re: Undefined Variable: expire
Posted: Tue Nov 07, 2017 4:23 pm
by vytasm
Regarding this error I found almost same code in "system\library\cache.php" on line 5
Code: Select all
public function __construct($adaptor, $expire = 3600) {
$class = 'Cache\\' . $adaptor;
So it looks like constructor is missing one parameter, if I am right You need to add second parameter "
$expire = 3600" in "system\library\template.php" file on line 5
Code: Select all
public function __construct($adaptor, $expire = 3600) {
$class = 'Template\\' . $adaptor;
Re: Undefined Variable: expire
Posted: Sat Nov 18, 2017 5:13 am
by windows95
Thanks for the fix. Both expiration edits worked like a charm
Re: Undefined Variable: expire
Posted: Mon Jan 08, 2018 5:36 pm
by DevJet
for some reason $expire is undefined therefore it will throw this error.
My fix is
<?php
class Template {
private $adaptor;
public function __construct($adaptor) {
$class = 'Template\\' . $adaptor;
if (class_exists($class)) {
// add $expire="" to clear "undefined variable warning" -reason
$expire="";
$this->adaptor = new $class($expire);
} else {
throw new \Exception('Error: Could not load template adaptor ' . $adaptor . '!');
}
}
public function set($key, $value) {
$this->adaptor->set($key, $value);
}
public function render($template) {
return $this->adaptor->render($template);
}
}
Re: Undefined Variable: expire
Posted: Fri Jun 01, 2018 3:11 am
by huntbee
I have created an
ocmod plugin for this fix. You can download it for
free from
https://www.huntbee.com/fix-for-undefin ... e-opencart
Re: Undefined Variable: expire
Posted: Mon Feb 11, 2019 7:00 pm
by tingwing
vytasm wrote: ↑Tue Nov 07, 2017 4:23 pm
Regarding this error I found almost same code in "system\library\cache.php" on line 5
Code: Select all
public function __construct($adaptor, $expire = 3600) {
$class = 'Cache\\' . $adaptor;
So it looks like constructor is missing one parameter, if I am right You need to add second parameter "
$expire = 3600" in "system\library\template.php" file on line 5
Code: Select all
public function __construct($adaptor, $expire = 3600) {
$class = 'Template\\' . $adaptor;
thanks!
Re: Undefined Variable: expire
Posted: Wed Feb 13, 2019 12:56 pm
by harap
Thank you tingwing. Your advise fixed the same problem of my site.