component-ini
component-ini copied to clipboard
Mismatch between encoding and decoding of boolean values.
IniWriter's encode method encodes boolean values as either 1 or 0, but IniReader's decode reads 1 and 0 as integer values. When reading and writing the same .ini file array using the library, all boolean values will be converted to integers.
Hello @high-rolls can you please provide us with the following information to help us better triage this issue?
- Current Behaviour or What happened?
- Expected Behaviour or What should happen?
- How can this be reproduced?
- Customer or Website Name
- On Prem or Cloud
- Matomo major version including minor / patch version
- PHP version
- Database
- What browsers are you seeing the problem on?
- Relevant log output and/or screenshots
Thank you in advance.
Hello @achakko , here's the information you need:
- Using an object of the IniWriter class to write boolean values will write them as 0 or 1 to a file. Later, when I read from the same file using an IniReader object, I get an array containing integer values where the booleans should be, because the numbers 0 and 1 are interpreted as integers.
- The IniWriter class should write the standard values for booleans, 'true' and 'false', which are already read correctly as booleans by the IniReader class.
- With the following code:
<?php
require 'vendor/autoload.php';
use Matomo\Ini\{IniReader, IniWriter};
$writer = new IniWriter();
$iniArray = ['Section 1' => ['test' => true]];
$writer->writeToFile('bool_test.ini', $iniArray);
$reader = new IniReader();
$readArray = $reader->readFile('bool_test.ini');
echo gettype($readArray['Section 1']['test']); // 'boolean' expected, got 'integer' instead
?>
- I'm not a customer, I'm just using this library for a personal project.
- N/A
- I use only this component, version 3.0.1
- PHP version 8.2.12
- N/A
- N/A
- N/A #
Also, here's the linked PR: #26