We would like to create a module for our project called Memcached
. This way we can have namespaced services (e.g. MemcachedServiceGet
) which perform actions using php’s installed Memcached
class.
However, we notice the following lines in zendframework/zend-modulemanager/src/Listener/ModuleResolverListener.php
if (class_exists($moduleName)) {
return new $moduleName;
}
This means that if we name our module Memcached
, then loading the module simply will not work. The module will be instantiated as a Memcached
object rather than the desired MemcachedModule
object.
So, is there any way we can simply name our module Memcached
? Or, do we need to be more creative and name our module something like MemcachedModule
? We would prefer not to do the latter since none of our other modules have this Module
suffix.
2
Answers
Zend Framework 3 has been patched so that a module may be named the same as an existing class. The following code was added to the
ModuleResolverListener
:So now, for example, we can create our own Zend Module called
MemcachedModule
which will not conflict with php's built inMemcached
class.For more info, view the patch on GitHub.
Module is Zend thing written using PHP Classes. You cant have two classes with same name, so you also cant import “module class” and “own class” with same name, but this is related only if you working in one namespace. You can access classes by full namespace. Here is some example.