Zf2 does not accept PHP 5 "DateTime" class

I ran into a very dangerous problem

I am trying to use the new php class "DateTime" for the date. I am using the latest version of php 5.3.12.

The code works fine when I use regular PHP code. (I mean another application without Zend), but when I used the same code in the controller, it gives me an error

Fatal error: Class 'User \ Controller \ DateTime' not found in C: \ wamp \ www \ 1625 \ module \ User \ src \ User \ Controller \ UserController.php on line 65

I did not understand, because "DateTime" is a php inbuild class

Code below

$date = new DateTime(date('Y').'-'.date('m').'-01'); echo "<li>".$date_now = $date->format('Ym-d'); 
+4
source share
1 answer

Since you are inside the namespace, you must call the DateTime base class as

 $date = new \DateTime(date('Y').'-'.date('m').'-01'); 

which for clarity you can rewrite as

 $date = new \DateTime(date('Ym-01')); 
+9
source

Source: https://habr.com/ru/post/1492877/


All Articles