Skip to content

Commit

Permalink
Use "toArray()" when available.
Browse files Browse the repository at this point in the history
Type casting object implementing ArrayAccess does not yield the expected array.
  • Loading branch information
ADmad committed Oct 13, 2015
1 parent 286ba0f commit b6eb79e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Utility/Hash.php
Expand Up @@ -156,6 +156,9 @@ public static function extract($data, $path)
list($token, $conditions) = self::_splitConditions($token);

foreach ($context[$_key] as $item) {
if (is_object($item) && method_exists($item, 'toArray')) {
$item = $item->toArray();
}
foreach ((array)$item as $k => $v) {
if (static::_matchToken($k, $token)) {
$next[] = $v;
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Utility/HashTest.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Test\TestCase\Utility;

use ArrayObject;
use Cake\ORM\Entity;
use Cake\TestSuite\TestCase;
use Cake\Utility\Hash;

Expand Down Expand Up @@ -152,7 +153,7 @@ public static function articleData()
public static function articleDataObject()
{
return new ArrayObject([
new ArrayObject([
new Entity([
'Article' => new ArrayObject([
'id' => '1',
'user_id' => '1',
Expand Down

0 comments on commit b6eb79e

Please sign in to comment.