2013-03-21 139 views
2

中重新声明date_diff()我使用了cakephp版本1.1.7692。错误致命错误:无法在

当我用PHP运行它版本> 5.3.2,它具有缺陷:

Fatal error: Cannot redeclare date_diff(). 

,我用PHP版本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和方法的原因解决? 谢谢大家。

+0

的数量。 6.2.9 ...它甚至没有发布! –

+0

@DiegoAgulló 对不起。我很困惑。它是5.2.9 – Hyeongsik

+0

@Hyeongsik +1从我这里。 –

回答

3

date_diff内置函数php版本5.3.0您不能重新声明它。

+0

是的。它是内置的函数在PHP中。我不编辑任何东西,但它有一个错误。 – Hyeongsik

+0

如果您希望代码向后兼容,只需使用'function_exists'来避免重新声明,如果函数本地实现的话。 –

+0

不是它的bug。它是在PHP 5.3.0版本中添加的。因为它在5.3.2中给出了错误,而在5.2.9中没有给出错误。 –

3

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上的时间差以获取更多信息。

注:在< 5.3.0版本的,我只是用这个形式计算出你不能运行版本的PHP什么天

<?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)); 
?> 
+0

我是将函数date_diff更改为其他名称。但它仍然如此。 – Hyeongsik

+0

@Hyeongsik date_diff()使用5.3.0及以上版本的php。 –

+0

@Hyeongsik编辑我的答案可能会帮助你。 –