PHP code example of bermudaphp / data-object

1. Go to this page and download the library: Download bermudaphp/data-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/ */

    

bermudaphp / data-object example snippets


$obj = new DataObj(['name' => 'Sarah', 'age' => 25]);
or
$data = new StdClass();

$data->name = 'Sarah';
$data->age = 25;

$obj = new DataObj($data);

$name = $obj->name; // Sarah;
$sex = $obj->get('sex', 'woman'); // woman
$name = $obj['name']; // Sarah

foreach($obj as $name => $value) echo 'property name: ' . $name . 'property value: ' . $value ;

isset($object->name); // true
$obj->has('name'); // true
isset($obj['name']) // true
$obj->offsetExists('name') // true

$obj->sex = 'woman';
$obj->set('sex', 'woman');
$obj['sex'] = 'woman';

unset($obj->sex);
$obj->remove('sex');
$obj->offsetUnset('sex');
unset($obj['sex']);