bermudaphp / data-object
v1.0
2023-03-03 13:10 UTC
Requires
- php: ^8.0|^8.1
- bermudaphp/arrayable: ^v1.0
This package is auto-updated.
Last update: 2024-10-30 02:26:46 UTC
README
composer require bermudaphp/data-object
Create
$obj = new DataObj(['name' => 'Sarah', 'age' => 25]); or $data = new StdClass(); $data->name = 'Sarah'; $data->age = 25; $obj = new DataObj($data);
Get property
$name = $obj->name; // Sarah; $sex = $obj->get('sex', 'woman'); // woman $name = $obj['name']; // Sarah
Iteration
foreach($obj as $name => $value) echo 'property name: ' . $name . 'property value: ' . $value ;
Exist property
isset($object->name); // true $obj->has('name'); // true isset($obj['name']) // true $obj->offsetExists('name') // true
Set property
$obj->sex = 'woman'; $obj->set('sex', 'woman'); $obj['sex'] = 'woman';
Remove property
unset($obj->sex); $obj->remove('sex'); $obj->offsetUnset('sex'); unset($obj['sex']);