What is difference or benefit between these to ways of configuration, use of ::class or not?
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => Controller\IndexController::class
)
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController'
)
),
Using the magic class constant will make your code more readable and easier to refactor. Only downside it's only supported for PHP 5.5 and higher, but you should be using that anyway.
The main benefit of using the class
keyword, apart from having shorter code, is that you can then take advantage of namespaces.
For example, if you had an initial use
clause
use Application\Controller\IndexController
then in your code you can use only
IndexController::class
This has also the effect that, if your class changes its namespace, you'll have to change it only in the use clauses, and not for every occurrence in your files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.