- Notifications
You must be signed in to change notification settings - Fork2k
Open
Description
PHP Version
8.2
CodeIgniter4 Version
4.5.5
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Windows, Linux
Which server did you use?
apache
Database
MySQL
What happened?
New registrar with the same method with other registrars replaces their contents on array_merge which works on only first level array. I hope array_merge_recursive will be better for modules
Steps to Reproduce
\Codeigniter\Config\BaseConfig
/** * Provides external libraries a simple way to register one or more * options into a config file. * * @return void * * @throws ReflectionException */protectedfunctionregisterProperties() {if (!static::$moduleConfig->shouldDiscover('registrars')) {return; }if (!static::$didDiscovery) {$locator =service('locator');$registrarsFiles =$locator->search('Config/Registrar.php');foreach ($registrarsFilesas$file) {$className =$locator->findQualifiedNameFromPath($file);if ($className ===false) {continue; }static::$registrars[] =new$className(); }static::$didDiscovery =true; }$shortName = (newReflectionClass($this))->getShortName();// Check the registrar class for a method named after this class' shortNameforeach (static::$registrarsas$callable) {// ignore non-applicable registrarsif (!method_exists($callable,$shortName)) {continue;// @codeCoverageIgnore }$properties =$callable::$shortName();if (!is_array($properties)) {thrownewRuntimeException('Registrars must return an array of properties and their values.'); }foreach ($propertiesas$property =>$value) {if (isset($this->{$property}) &&is_array($this->{$property}) &&is_array($value)) {$this->{$property} =array_merge($this->{$property},$value); }else {$this->{$property} =$value; } } } }
Expected Output
Expected merge the old contents array with the new one
Anything else?
Yes i used array_merge_recursive. I discovered the issue to so i extend the base config to child class today fix this but i think the usage of array_merge_recursive is a better option help on this to update the core code
\Codeigniter\Config\BaseConfig
/** * Provides external libraries a simple way to register one or more * options into a config file. * * @return void * * @throws ReflectionException */protectedfunctionregisterProperties() {if (!static::$moduleConfig->shouldDiscover('registrars')) {return; }if (!static::$didDiscovery) {$locator =service('locator');$registrarsFiles =$locator->search('Config/Registrar.php');foreach ($registrarsFilesas$file) {$className =$locator->findQualifiedNameFromPath($file);if ($className ===false) {continue; }static::$registrars[] =new$className(); }static::$didDiscovery =true; }$shortName = (newReflectionClass($this))->getShortName();// Check the registrar class for a method named after this class' shortNameforeach (static::$registrarsas$callable) {// ignore non-applicable registrarsif (!method_exists($callable,$shortName)) {continue;// @codeCoverageIgnore }$properties =$callable::$shortName();if (!is_array($properties)) {thrownewRuntimeException('Registrars must return an array of properties and their values.'); }foreach ($propertiesas$property =>$value) {if (isset($this->{$property}) &&is_array($this->{$property}) &&is_array($value)) {$this->{$property} =array_merge_recursive($this->{$property},$value); }else {$this->{$property} =$value; } } } }
Metadata
Metadata
Assignees
Labels
No labels