我用的是5号小提琴.我试着用
$now = DateTime();
$timestamp = $now->getTimestamp();
但它显示了这样的错误.
FatalErrorException in ProjectsController.php line 70:
Call to undefined function App\Http\Controllers\DateTime()
我能做什么?
我用的是5号小提琴.我试着用
$now = DateTime();
$timestamp = $now->getTimestamp();
但它显示了这样的错误.
FatalErrorException in ProjectsController.php line 70:
Call to undefined function App\Http\Controllers\DateTime()
我能做什么?
DateTime
不是函数,而是class.
当您只引用一个类(如new DateTime()
PHP)时,会搜索current namespace中的类.然而,DateTime
类显然不存在于您的控制器名称空间中,而是存在于根名称空间中.
您可以通过前缀反斜杠在根名称空间中引用它:
$now = new \DateTime();
Or add an import statement at the top:
use DateTime;
$now = new DateTime();