PHP code example of etconsilium / php-recursive-array-object

1. Go to this page and download the library: Download etconsilium/php-recursive-array-object library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

etconsilium / php-recursive-array-object example snippets


use \RecursiveArrayObject as JSObject;

$test = [
    'a' => [
        'foo' => 42,
        'bar' => [
            'tyk', 'myk'
        ]
    ]
];

$q = new JSObject($test);
$p = new ArrayObject($test, ArrayObject::ARRAY_AS_PROPS);

print_r($q->a->foo);
print_r($q->a->bar);
/**
 *
42
RecursiveArrayObject Object
(
    [storage:ArrayObject:private] => Array
        (
            [0] => tyk
            [1] => myk
        )

)
 */


print_r($p->a->foo);
print_r($p->a->bar);
/**
 *
PHP Notice:  Trying to get property of non-object
PHP Notice:  Trying to get property of non-object
 */