You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: getDI() returns null but declares DiInterface (InjectionAwareInterface, AbstractInjectionAware and 5 classes) #17787
Phalcon\Di\AbstractInjectionAware::getDI() declares the return type Phalcon\Di\DiInterface (phalcon/Di/AbstractInjectionAware.zep:30), but it returns null when no container is set. Phalcon\Di\InjectionAwareInterface::getDI() declares the same return type (phalcon/Di/InjectionAwareInterface.zep:22).
Five other classes declare the same return type, and their container property can be null too:
Class
File
Phalcon\Session\Bag
phalcon/Session/Bag.zep:89
Phalcon\Mvc\Model\Manager
phalcon/Mvc/Model/Manager.zep:1168
Phalcon\Mvc\Model\Query
phalcon/Mvc/Model/Query.zep:546
Phalcon\Mvc\Model\Transaction\Manager
phalcon/Mvc/Model/Transaction/Manager.zep:164
Phalcon\Mvc\View\Engine\Volt\Compiler
phalcon/Mvc/View/Engine/Volt/Compiler.zep:2091
A release PHP build does not check the return type of internal functions. The caller gets null.
A PHP debug build (--enable-debug) checks the return type and stops with a fatal error.
Code in Phalcon already expects null. For example, Phalcon\Http\Request::resolveAuthorizationHeaders() calls getDI() and then checks container !== null.
The PHP implementation (phalcon/phalcon) already declares DiInterface | null for these 7 methods.
Fatal error: Phalcon\Di\AbstractInjectionAware::getDI(): Return value must be of type Phalcon\Di\DiInterface, null returned
The test suite stops at the same error in tests/unit/Http/Request/GetHeadersTest.php:40 (Request::getHeaders() -> resolveAuthorizationHeaders() -> getDI()). With a release PHP build, the same script prints NULL.
Expected behavior
The declared return types agree with the returned values, the same as the PHP implementation.
Possible fix
Declare the return type <DiInterface> | null for the 7 methods:
publicfunctiongetDI() -><DiInterface> | null
The returned values do not change. A class that implements InjectionAwareInterface, or extends one of these classes, and declares the return type DiInterface stays compatible. Phalcon\Di\Injectable, Phalcon\Http\Response, Phalcon\Mvc\Model\Criteria, Phalcon\Mvc\Model\MetaData, Phalcon\Mvc\Model\Query\Builder and Phalcon\Tag keep DiInterface, the same as the PHP implementation.
Activity