Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function get($path, $default = null)
}

if ($this->separator === null || $this->separator === '' || !\strpos($path, $this->separator)) {
return (isset($this->data->$path) && $this->data->$path !== null && $this->data->$path !== '')
return (isset($this->data->$path) && $this->data->$path !== '')
? $this->data->$path
: $default;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ public function get($path, $default = null)
#[\ReturnTypeWillChange]
public function getIterator()
{
return new \ArrayIterator($this->toArray());
return new \ArrayIterator((array) $this->data);
}

/**
Expand Down Expand Up @@ -592,7 +592,7 @@ public function remove($path)
{
// Cheap optimisation to direct remove the node if there is no separator
if ($this->separator === null || $this->separator === '' || !\strpos($path, $this->separator)) {
$result = (isset($this->data->$path) && $this->data->$path !== null && $this->data->$path !== '')
$result = (isset($this->data->$path) && $this->data->$path !== '')
? $this->data->$path
: null;

Expand Down
32 changes: 32 additions & 0 deletions tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,38 @@ public function testRemoveOffsetAsAnArray()
$this->assertFalse(isset($instance['foo.bar']));
}

/**
* @testdox Mixed types are correctly stored and identified
*
* @covers \Joomla\Registry\Registry
*/
public function testMixedTypesInRegistry()
{
$instance = new Registry();
$instance->set('string', 'hello');
$instance->set('integer', 42);
$instance->set('array', ['a', 'b', 'c']);
$instance->set('object', new \stdClass());
$instance->set('registry', new Registry());

$expected = [
'string' => ['type' => 'string'],
'integer' => ['type' => 'integer'],
'array' => ['type' => 'array'],
'object' => ['type' => 'object', 'class' => \stdClass::class],
'registry' => ['type' => 'object', 'class' => Registry::class],
];

foreach ($instance as $key => $value) {
$this->assertArrayHasKey($key, $expected, "Unexpected key '$key' found.");
$this->assertSame($expected[$key]['type'], gettype($value), "Type mismatch for key '$key'.");

if ($expected[$key]['type'] === 'object') {
$this->assertInstanceOf($expected[$key]['class'], $value, "Class mismatch for key '$key'.");
}
}
}

/**
* @testdox A value is stored to the Registry
*
Expand Down