【问题标题】:The bug Fatal error: Cannot redeclare date_diff() in错误致命错误:无法重新声明 date_diff() in
【发布时间】:2013-03-10 19:30:06
【问题描述】:

我使用的 cakephp 版本是 1.1.7692。

当我使用 php ver > 5.3.2 运行它时,它有错误:

Fatal error: Cannot redeclare date_diff().

我使用 php ver 5.2.9 运行它,它显示的文本和代码与:

quality = 100; $thumb->fileName = "/path/to/file.jpg"; //IMPORTANT -
must run init() function before any manipulation is performed
$thumb->init(); //shrink image by 50% $thumb->percent = 50;
$thumb->resize(); //crop image to 350x350 from center of image
$thumb->cropSize = 350; $thumb->crop(); //resize image to no more than
125px wide $thumb->percent = 0; $thumb->maxWidth = 125;
$thumb->resize(); //save image as 'filename.jpg'
$thumb->save('/path/to/save/filename.jpg'); You can also use this
class to dynamically generate thumbnails and display them After you
have made your manipulations you could display the result by: echo '';
*/ class ThumbnailComponent extends Object { var $errmsg;    //error message to parse var $error;    //flag for whether there is an error var
$format;     //file format of image var $currentDimensions=array(); 
//current dimensions of working image var $newDimensions=array();   
//new dimensions after manipulation var $newImage;   //final image to
be displayed/saved var $oldImage;    //original image to be manipulated
var $workingImage;   //working image being manipulated var $fileName;   
//filename of image, can include directory var $maxWidth;    //maximum
width of the image var $maxHeight;   //maximum height of the image var
$percent;    //percentage of the original image size var $quality;  
//image quality of jpeg images var $cropSize;....

这是函数 date_diff :

function date_diff($start_date,$end_date)
    {
        $splitstdate = split(" ",$start_date); 
        $splitenddate = split(" ",$end_date); 

        list($year,$month,$day)=split("-",$splitstdate[0]);
        list($year_test,$month_test,$day_test)=split("-",$splitenddate[0]);


        list($hour,$min,$sec)=split(":",$splitstdate[1]);
        list($hour_test,$min_test,$sec_test)=split(":",$splitenddate[1]);

        $start = mktime($hour, $min, $sec,$month,$day,$year);
        $end = mktime($hour_test, $min_test,$sec_test,$month_test,$day_test,$year_test);
        $date_diff =   $start-$end;
        if($date_diff<0)
        $date_diff=0;
        $days = intval($date_diff /(3600*24)) ; 

        $hms = date('h \h\r \m\i\n s \s\e\c \a\g\o',$date_diff);
        return $days.' days '.$hms ;
}

谁能知道bug的原因和解决方法? 谢谢大家。

【问题讨论】:

  • 你不能用 php 版本运行任何东西。 6.2.9……还没发布呢!
  • @DiegoAgulló 对不起。我很困惑。它是 5.2.9
  • @Hyeongsik +1 来自我。

标签: php datediff redeclare


【解决方案1】:

date_diffphp 版本5.3.0 中的内置函数,不能重新声明。

【讨论】:

  • 是的。它是 php 中的内置函数。我没有编辑任何东西,但它有一个错误。
  • 如果您希望代码向后兼容,只需使用function_exists,以避免在本机实现的情况下重新声明。
  • 不,这不是错误。它是在 php 版本 5.3.0 中添加的。因此,它在 5.3.2 中而不是在 5.2.9 中给出错误。
  • @YogeshSuthar,你的意思是它需要 php ver 5.3.0 吗?
  • @Hyeongsik 是的,它需要 5.3.0 版。
【解决方案2】:

date_diff() 是 php 5.3.0 版本的内置函数。及以上版本,你可以检查http://php.net/manual/en/function.date-diff.php 这就是为什么你会得到Fatal error: Cannot re-declare date_diff() 所以改变你的函数名这将解决你的问题

您可以查看我对日期差异的回答https://stackoverflow.com/a/14938421/718224 了解更多信息。

注意:

<?php
$today = strtotime("2011-02-03 00:00:00");
$myBirthDate = strtotime("1964-10-30 00:00:00");
printf("I'm %d days old.", round(abs($today-$myBirthDate)/60/60/24));
?>

【讨论】:

  • 我将函数 date_diff 更改为其他名称。但它仍然如此。
  • @Hyeongsik date_diff() 使用5.3.0及以上版本的php。
  • 感谢@Advait Amin,我在 php 5.0 版上运行正常。但现在我无法进入 phpadmin,因为它需要 php 5.2+。请帮帮我?
  • @Hyeongsik,你为什么不接受答案???我的回答对你有帮助吗???
  • 我试试你的方法。但我无法解决我的问题。所以我选择methos升级版本cakephp 1.1到1.3。
猜你喜欢
  • 1970-01-01
  • 2010-12-29
  • 2015-08-29
  • 2012-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多