Post by renegadomty » Fri Jun 17, 2016 3:29 am

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.

Newbie

Posts

Joined
Fri Jun 17, 2016 3:24 am

Post by doktorek » 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

New member

Posts

Joined
Thu Apr 28, 2016 8:40 pm

Post by damodaranudas » Tue Apr 04, 2017 2:00 am

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 :)

User avatar
Newbie

Posts

Joined
Tue Nov 20, 2012 1:20 am
Location - Colombia

Post by burley » Thu Apr 20, 2017 4:39 pm

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?!

User avatar
Active Member

Posts

Joined
Sun Oct 09, 2011 3:30 pm

Post by artcore » Thu Apr 20, 2017 5:07 pm

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.

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by burley » Thu Apr 20, 2017 5:17 pm

Will defenitly give that a try!

Thanks!!

User avatar
Active Member

Posts

Joined
Sun Oct 09, 2011 3:30 pm

Post by vytasm » 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;

Newbie

Posts

Joined
Wed Feb 01, 2012 5:28 pm

Post by windows95 » Sat Nov 18, 2017 5:13 am

Thanks for the fix. Both expiration edits worked like a charm

Newbie

Posts

Joined
Wed Aug 16, 2017 6:22 am

Post by DevJet » Mon Jan 08, 2018 5:36 pm

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);
}
}

Newbie

Posts

Joined
Mon Dec 18, 2017 7:37 am

Post by huntbee » Fri Jun 01, 2018 3:11 am

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

HuntBee OpenCart Services
https://www.huntbee.com


User avatar
New member

Posts

Joined
Sun Nov 01, 2015 4:01 am
Location - India

Post by tingwing » Mon Feb 11, 2019 7:00 pm

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!

my extension:https://www.opencart.com/index.php?rout ... estshop24h
email :support@bestshop24h.com
site:http://www.bestshop24h.com


Active Member

Posts

Joined
Tue Aug 02, 2016 9:01 pm

Post by harap » Wed Feb 13, 2019 12:56 pm

Thank you tingwing. Your advise fixed the same problem of my site.

Active Member

Posts

Joined
Wed Sep 16, 2015 12:34 am
Location - United States
Who is online

Users browsing this forum: No registered users and 23 guests