jayankaghosh / dataobject
A wrapper class that supports all types of getX, setX, and unsX methods. Inspired by Magento's DataObect
Package info
github.com/jayankaghosh/data-object
Type:php-extension
pkg:composer/jayankaghosh/dataobject
dev-master
2022-02-11 08:52 UTC
This package is auto-updated.
Last update: 2026-03-11 18:43:13 UTC
README
A wrapper class that supports all types of getX, setX, and unsX methods. Inspired by Magento's DataObect
Installation
composer require jayankaghosh/dataobject
Usage
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Basic
$dataObject = new \DataObject\DataObject(); // Create an object of DataObject
$dataObject->setMessage('Hello PHP'); // Even though method setMessage is not defined anywhere
echo $dataObject->getMessage(); // We still get the output as "Hello PHP"
// Default Values
$dataObject = new \DataObject\DataObject(['nuclear_code' => 12345]); // Create an object of DataObject. Notice we passed an array into the constructor
$dataObject->setMessage('Hello PHP'); // Even though method setMessage is not defined anywhere
echo $dataObject->getMessage(); // We still get the output as "Hello PHP"
echo $dataObject->getNuclearCode(); // And calling this method gives us the output as "12345" because of the default values passed in the constructor
// getData and setData
$dataObject = new \DataObject\DataObject();
$dataObject->setData('name', 'bond...james bond'); // This will save the value with the key 'name'
echo $dataObject->getData('name'); // Which we can later retrieve like this
echo $dataObject->getName(); // or this