Description
The Bug
There are multiple methods in CodeIgniter\Config\Services that make calls to other methods in the class using the form static::someMethod()
.
For instance, see CodeIgniter\Config\Services::renderer() where the last line in the method is
return new \CodeIgniter\View\View(
$config,
$viewPath,
static::locator(true),
CI_DEBUG,
static::logger(true) // local scope!!!
);
The problem is that any overriding service defined in APPPATH/Config/Services.php is not in scope so the core class is delivered and not the extended one.
The following services are all called using the static::someMethod()
form and so cannot be extended.
- logger
- request
- response
- locator
- routes
- cache
- renderer
And I might have missed some. There are quite a few CodeIgniter\Config\Services that make static calls to those services so the ramifications would conceivably multiply.
CodeIgniter version
CI 4.0.0-rc.3 at commit 2c04e1c (10/28/19)
Affected module
Services
Reproducing the Problem
Extend Logger
<?php
namespace App\Log;
use Psr\Log\LoggerInterface;
use CodeIgniter\Log\Logger;
class Logger extends Logger implements LoggerInterface
{
public function myNewMethod($message)
{
echo "New Logger Method says: $message";
}
}
In APPPATH/Config/Services.php
public static function logger(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('logger');
}
return new \App\Log\Logger(new \Config\Logger\Logger());
}
In a controller (of your choice)
$this->logger->myNewMethod('There be Dragons!');
Produces the following error
Call to undefined method CodeIgniter\Log\Logger::myNewMethod()
Context
- OS: Linux (Debian 9)
- Web server Apache version 2.4.25
- PHP version 7.2.17
Activity