adbario / php-dot-notation

Dot notation access to PHP arrays

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to parse arrays containing objects

danielsetreus opened this issue · comments

Considering the following array:

$arr = array(
        'foo' => array(
            'bar' => 'inner value'
        ),
        'fooObj' => (object) array(
            'objAttribute' => 'some value'
        ),
);

$dot = new \Adbar\Dot($arr);

var_dump($dot->has('foo.bar')); // bool(true)
var_dump($dot->has('fooObj.objAttribute')); // bool(false)

Would it be possible to extend Dot to also include objects (nested or not nested inside arrays).

Yes it is possible. The only issue that I can think of is how do you know which to use when you flatten and unflatten it?

A user of this library may have to make a choice to use associative arrays or objects, and silently coerce the data structure to be stored consistently and behave consistently.

It's unfortunate that associative arrays and objects are so similar, if you write something to make a class compatible with object and array syntax you have to implement two interfaces to make it friendly for both access methods. 🤒 🤕

Oh yeah, and a function to differentiate an indexed array from an associative array. Do the indexes need to be contiguous and start from 0? Or is the fact they are all numeric good enough? Down the 🐰 hole....

Closing due to inactivity.