Description
Symfony version(s) affected
3.2.0-current
Description
Since #20232, IniFileLoader no longer works correctly with ini files containing arrays:
Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\DependencyInjection\Loader\IniFileLoader::phpize() must be of the type string, array given, called in vendor/symfony/dependency-injection/Loader/IniFileLoader.php on line 44 and defined in vendor/symfony/dependency-injection/Loader/IniFileLoader.php on line 72
Call Stack:
1. {main}()
2. Symfony\Component\DependencyInjection\Loader\XmlFileLoader->load()
3. Symfony\Component\DependencyInjection\Loader\XmlFileLoader->parseImports() vendor/symfony/dependency-injection/Loader/XmlFileLoader.php:59
4. Symfony\Component\DependencyInjection\Loader\FileLoader->import() vendor/symfony/dependency-injection/Loader/XmlFileLoader.php:111
5. Symfony\Component\Config\Loader\FileLoader->import() vendor/symfony/dependency-injection/Loader/FileLoader.php:66
6. Symfony\Component\Config\Loader\FileLoader->doImport() vendor/symfony/config/Loader/FileLoader.php:104
7. Symfony\Component\DependencyInjection\Loader\IniFileLoader->load() vendor/symfony/config/Loader/FileLoader.php:165
8. Symfony\Component\DependencyInjection\Loader\IniFileLoader->phpize() vendor/symfony/dependency-injection/Loader/IniFileLoader.php:44
Previously, per the default behaviour of INI_SCANNER_NORMAL
, the loader would always return values as string|string[]
. There were some possible value substitutions, eg "true"
became "1"
, however the deepest nested values were always a string.
The linked PR added intermediate parsing to convert these values to other scalar types, but incorrectly assumes the only possible input type is string
. (Since version 4.4, this is by typehinting the private method's parameter, and before that by immediately calling \rtrim
on the value.) This conversion isn't mentioned at all in the upgrading notes and there's still a caution in the docs suggesting other types aren't supported.
How to reproduce
Load a config file such as:
[parameters]
this.works = true
these.work[] = false
these.fail[] = true
Expected values:
[
"this.works" => true,
"these.work" => [
false
],
"these.fail" => [
true
]
]
Actual behaviour: TypeError
thrown
Possible Solution
IniFileLoader::load
should call \is_array
on each parameter value, and when true call IniFileLoader::phpize
for each array element instead of passing the entire array only once.
Additional Context
No response