diff --git a/CHANGELOG.md b/CHANGELOG.md index 9473aa2..2480338 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ All notable changes to this project will be documented in this file, in reverse method could not be invoked as documented previously, these changes are considered bugfixes and not BC breaks. +- [#96](https://github.com/zendframework/zend-hydrator/pull/96) fixes issue with integer keys in `ArraySerializableHydrator`. Keys are now + cast to strings as we have strict type declaration in the library. + ## 3.0.0 - 2018-12-10 ### Added diff --git a/src/ArraySerializableHydrator.php b/src/ArraySerializableHydrator.php index 06ffb32..70060cd 100644 --- a/src/ArraySerializableHydrator.php +++ b/src/ArraySerializableHydrator.php @@ -36,6 +36,8 @@ public function extract(object $object) : array $filter = $this->getFilter(); foreach ($data as $name => $value) { + $name = (string) $name; + if (! $filter->filter($name)) { unset($data[$name]); continue; diff --git a/test/ArraySerializableHydratorTest.php b/test/ArraySerializableHydratorTest.php index 4d9d3e7..e93cc4e 100644 --- a/test/ArraySerializableHydratorTest.php +++ b/test/ArraySerializableHydratorTest.php @@ -9,6 +9,7 @@ namespace ZendTest\Hydrator; +use ArrayObject; use PHPUnit\Framework\TestCase; use TypeError; use Zend\Hydrator\ArraySerializableHydrator; @@ -169,4 +170,17 @@ public function testHydrationWillReplaceNestedArrayData($start, $submit, $expect $this->assertSame($expected, $final['tags']); } + + public function testExtractArrayObject() + { + $arrayObject = new ArrayObject([ + 'value1', + 'value2', + 'value3', + ]); + + $data = $this->hydrator->extract($arrayObject); + + $this->assertSame(['value1', 'value2', 'value3'], $data); + } }