Zen Cart Logo
Forums / General Questions / PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Locked

Views: 15,433

Results 1 to 15 of 15
This thread is locked. New replies are disabled.
5 Jul 2011, 9:37 PM
#1
jami1955 avatar

jami1955

New Zenner

Join Date:
Feb 2008
Location:
Boulder, CO, Dec 2: India
Posts:
89
Plugin Contributions:
0

PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

I'm using v. 1.3.8a with all security patches. I can't afford to upgrade to 1.3.9 right now. I just changed servers, within the same host, so they migrated everything, and all other websites are working. But the PHP version is diff. now, and all pages within the zen cart are giving a blank page, and the error reads:

PHP Fatal error: Cannot redeclare date_diff() in ...(file path) /store/includes/functions/functions_general.php on line 1476

In post http://www.zen-cart.com/forum/showthread.php?t=141937 it is recommended to install the patches available from zen cart to take care of this error message. I have replaced the file with the file in the php 5.3 patch. **I'm still getting the blank page, and the same error. **

This is the code in the (new) file in question, lines 1472-1479:

 $date1_set = mktime(0,0,0, $m1, $d1, $y1);
    $date2_set = mktime(0,0,0, $m2, $d2, $y2);

    return(round(($date2_set-$date1_set)/(60*60*24)));
  }

/**

Does anyone see the problem???
thanks
JSC

5 Jul 2011, 10:55 PM
#2
jami1955 avatar

jami1955

New Zenner

Join Date:
Feb 2008
Location:
Boulder, CO, Dec 2: India
Posts:
89
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Have had the whole PHP 5.3 answer come as the reason why the zen cart is giving blank pages, had the reply from Dr. Byte to use the patch found here
http://www.zen-cart.com/forum/showthread.php?t=140960

-- thank you Dr. Byte.

I uploaded that patch, in total, double checked all files to be sure they are the right files, and uploaded to the right directories, and the problem still exists. In the original thread I mentioned the file and line # being:
/includes/functions/functions_general.php on line 1476

I have since checked on the original file (from a backup 7 days before I replaced the files from the patch recommended by Dr. Byte) - and lines 1465 - 1480 are exactly the same. There is no difference in this file where the error log is locating a fatal error.

Could it be, there is something more needed here in this file? Or are we absolutely sure that file is fixed? I'm happy if you close this thread also Dr. Byte, but I've been using zen cart since 2006, and despite what is listed under my user name, I'm not a beginner.

thanks
JSC

6 Jul 2011, 3:19 AM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

You REALLY need to upgrade to the latest version.

6 Jul 2011, 2:11 PM
#4
jami1955 avatar

jami1955

New Zenner

Join Date:
Feb 2008
Location:
Boulder, CO, Dec 2: India
Posts:
89
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

That's exactly what I'm going to do. :wacko:

One of those improvements (php 5.3) which comes with a pretty high price tag.

6 Jul 2011, 2:56 PM
#5
vger avatar

vger

Past Contributor

Join Date:
Nov 2004
Location:
Norfolk, United Kingdom
Posts:
3,189
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

One of those improvements (php 5.3) which comes with a pretty high price tag.

Well, look at it this way, 1.3.8a is not secure and 1.3.9h is secure. It just so happens that 1.3.9h works with PHP 5.3.

As for PHP 5.2, 5.3 and 6, well that's just a mess up by the PHP Project:

Normally "deprecated" means "you can use it, but it's not recommended and we will remove it in a later version" but with the step-change from 5.2 to 5.3 certain functions are deprecated but means "it's not recommended and so you can't use it".

They should have upgraded the 5.2 series, with backward compatibility, and left the major changes to the 6 series.

They certainly weren't thinking of the people who actually use PHP (hosting companies) when they made the changes the way they did. I mean by this that with cPanel it's quite easy to offer customers the choice of two major versions (4 or 5), but there's no mechanism for offering variants of the same version (5.2 and 5.3). So hosting companies have to put in place their own side-by-side solution if they want to offer the choice of 5.2 or 5.3

Vger

30 Aug 2011, 4:37 AM
#6
cibertienda avatar

cibertienda

New Zenner

Join Date:
Feb 2010
Posts:
11
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

But Now I am having the problem with the PHP 5.3.6, and I have the 1.3.9h version of zencart Installed, Do you have any idea, how to fix it, Does someome knows about a patch? Please reply ASAP, I really need my admin back to work.

30 Aug 2011, 4:43 AM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Zen Cart v1.3.9h does NOT contain any files which would trigger a "cannot redeclare date_diff()" error message.
So, your problem must exist in one of the files you've added to the site via an addon or other customization.
You will need to find the file and make whatever appropriate adjustments are needed to that file to get rid of the error.

9 Dec 2011, 10:33 AM
#8
scientific_anomaly avatar

scientific_anomaly

New Zenner

Join Date:
Nov 2010
Posts:
44
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Well good morning from PHP 5.3.8 vs Zen Cart 1.3.9h

PHP Fatal error: Cannot redeclare date_diff()

more specifically:

PHP Fatal error: Cannot redeclare date_diff() in /home/serveraccount/public_html/admin/includes/functions/general.php on line 3017

Hosting upgrade simultaneously wiped out my 7 instances of zen cart admin interface to white screen of death (and probably 10s of thousands of others at a guess).

Useful fix located (applied to general.php)

From this:

// compute the days between two dates
function date_diff($date1, $date2) {
//$date1 today, or any other day
//$date2 date to check against

$d1 = explode("-", $date1);
$y1 = $d1[0];
$m1 = $d1[1];
$d1 = $d1[2];

$d2 = explode("-", $date2);
$y2 = $d2[0];
$m2 = $d2[1];
$d2 = $d2[2];

$date1_set = mktime(0,0,0, $m1, $d1, $y1);
$date2_set = mktime(0,0,0, $m2, $d2, $y2);

return(round(($date2_set-$date1_set)/(60*60*24)));

}

////

To this:

// compute the days between two dates
if (! function_exists(date_diff)) {
function date_diff($date1, $date2) {
//$date1 today, or any other day
//$date2 date to check against

$d1 = explode("-", $date1);
$y1 = $d1[0];
$m1 = $d1[1];
$d1 = $d1[2];

$d2 = explode("-", $date2);
$y2 = $d2[0];
$m2 = $d2[1];
$d2 = $d2[2];

$date1_set = mktime(0,0,0, $m1, $d1, $y1);
$date2_set = mktime(0,0,0, $m2, $d2, $y2);

return(round(($date2_set-$date1_set)/(60*60*24)));

}
}
////

i.e. adding this above: if (! function_exists(date_diff)) {

and this below: }

the pre-existing code.

Anyway this fudge if that is what it is has restored all 7 instances to functionality without any ill effects so far spotted. I suspect it might be useful to others while waiting for a more official bug fix.

9 Dec 2011, 10:55 AM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Um, there's no "bug fix" required except to say you're using old code.
See my last post.
V1.3.9 doesn't contain a "date_diff" function, because it was renamed to zen_date_diff.
Evidently your site needs an upgrade, not a bug fix.

9 Dec 2011, 3:54 PM
#10
scientific_anomaly avatar

scientific_anomaly

New Zenner

Join Date:
Nov 2010
Posts:
44
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Sir, in that case I am confused. Every instance of Zen Cart I have started life as a native 1.3.9h clean install, however most of what I have now is profoundly modified. i.e. another clean install of 1.3.9h is no longer a viable option.

If I have to assume that somewhere along that journey a module has overwritten admin/includes/general.php (or something else that can throw an error in that code) please will you advise whether what I have done with this

if (! function_exists(date_diff)) { } in general.php

is a genuine solution, or what exactly I should searching for, deleting or replacing it with in the code overall to restore the 1.3.9h state for this affected function.

I have noticed that you are not in the habit of spoon feeding rounded solutions however in this case I trust you will yield as I am concerned that I and others who are in the dark on this one may well have compromised security without realizing it - and in my case at least, I have to assume that I have defeated date_diff and am lacking the zen_date_diff function entirely with unknown consequences likely to ensue.

Thank you

9 Dec 2011, 4:23 PM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

You could probably start by comparing your general.php with one from a fresh v1.3.9h download, to get a sense of your differences.

9 Dec 2011, 4:24 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

It would be best if you were to put back the original Zen Cart code for the version you are running.
If you've installed addons which overwrite files with older code then you'll need to merge the changes the addon makes instead of blindly overwriting the original core files.
http://www.zen-cart.com/wiki/index.php/Troubleshoot_-_Diagnosing_Obscure_Issues

9 Dec 2011, 5:20 PM
#13
scientific_anomaly avatar

scientific_anomaly

New Zenner

Join Date:
Nov 2010
Posts:
44
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Many thanks. Can I get confirmation that it will be satisfactory to constrain my search to general.php in this instance (and hope anything mod'ed is also commented)

9 Dec 2011, 11:06 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

No, I wouldn't consider that to be sufficient scope, because I've NO idea how many or which files you've blindly replaced by outdated code from old incompatible addons.
You need to do a THOROUGH inspection, hence the link I posted earlier.

4 May 2012, 9:30 AM
#15
carl avatar

carl

New Zenner

Join Date:
Dec 2006
Location:
France
Posts:
62
Plugin Contributions:
0

Re: PHP ver. 5.3 -PHP Fatal error: Cannot redeclare date_diff() in

Thanks, this worked for me. I needed to keep this site going on a new server just for ref not public view, so great.
my new site is 1.9