https://github.com/bermudaphp/data-object
https://github.com/bermudaphp/data-object
data-object php
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bermudaphp/data-object
- Owner: bermudaphp
- License: mit
- Created: 2020-03-12T15:16:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T13:10:44.000Z (over 2 years ago)
- Last Synced: 2025-02-07T17:52:04.699Z (5 months ago)
- Topics: data-object, php
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Install
```bash
composer require bermudaphp/data-object
```
# Create
```php
$obj = new DataObj(['name' => 'Sarah', 'age' => 25]);
or
$data = new StdClass();$data->name = 'Sarah';
$data->age = 25;$obj = new DataObj($data);
```
# Get property
```php
$name = $obj->name; // Sarah;
$sex = $obj->get('sex', 'woman'); // woman
$name = $obj['name']; // Sarah
```
# Iteration
```php
foreach($obj as $name => $value) echo 'property name: ' . $name . 'property value: ' . $value ;
```
# Exist property
```php
isset($object->name); // true
$obj->has('name'); // true
isset($obj['name']) // true
$obj->offsetExists('name') // true
```
# Set property
```php
$obj->sex = 'woman';
$obj->set('sex', 'woman');
$obj['sex'] = 'woman';
```
# Remove property
```php
unset($obj->sex);
$obj->remove('sex');
$obj->offsetUnset('sex');
unset($obj['sex']);
```