Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 日期时间方法链接问题_Php - Fatal编程技术网

Php 日期时间方法链接问题

Php 日期时间方法链接问题,php,Php,这项工作: $aWeekAfterDate = new DateTime(); $aWeekAfterDate->modify('+1 week'); $aWeekAfterDate->format('d.m.Y'); 但这是: $aWeekAfterDate = new DateTime(); $aWeekAfterDate->modify('+1 week')->format('d.m.Y'); 给我这个错误: 致命错误:调用成员函数 中的非对象上的forma

这项工作:

$aWeekAfterDate = new DateTime(); 
$aWeekAfterDate->modify('+1 week');
$aWeekAfterDate->format('d.m.Y');
但这是:

$aWeekAfterDate = new DateTime(); 
$aWeekAfterDate->modify('+1 week')->format('d.m.Y');
给我这个错误:

致命错误:调用成员函数 中的非对象上的format()。。。在…上 行

致命错误(关机):调用 上的成员函数format() 非对象在。。。在线

我在文档中查找了该方法,其返回值如下:

返回方法的DateTime对象 失败时链接或错误

为什么方法链接不起作用


我使用的是PHP版本5.2.6。

Changelog

Version   Description 
5.3.0     Changed the return value on success from NULL to DateTime. 

因此,只有在PHP5.3.0中才引入了为链接返回DateTime对象,这很容易被忽略,除非您以前被它刺痛过