PHP code example of masnathan / object

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

    

masnathan / object example snippets


$myBigDataArray = array(
	'details' => array(
		'first_name' => 'André',
		'last_name' => 'Filipe',
		'email' => '[email protected]',
		'social' => array(
			'github' => 'https://github.com/MASNathan',
			'twitter' => 'https://twitter.com/masnathan'
		)
	),
	'account_info' => array(
		'admin' => true,
		'last_login' => 2015-06-13 13:37:00
	)
	'cart_items' => array(
		array('id' => 1337),
		// (...)
	)
);

$object = new SuperObject($myBigDataArray);

echo $object->getDetails()->getFirstName(); // 'André'
$object->getDetails()->isLastName('Roque'); // false
echo $object->getDetails()->getSocial()->getGithub(); // 'https://github.com/MASNathan'
echo $object->getDetails()->getSocial()->getFacebook(); // ''
$object->getAccountInfo()->isAdmin(); // true
$object->getAccountInfo()->unsetLastLogin(); // unsets $myBigDataArray['account_info']['last_login']

foreach ($object->getCartItems() as $item) {
	echo $item->getId(); // 1337
}

$object->toArray(); // array( ... )
$object->toObject(); // StdClass( ... )

unserialize(serialize($object));
// or as json
json_decode(json_encode($object));

 php
use MASNathan\SuperObject;

$object = new SuperObject();
$object->setMode('live');
$object->set('mode', 'live');
$object->mode = 'live';
$object['mode'] = 'live';

echo $object->getAppMode() // 'live'
echo $object->get('app_mode') // 'live'
echo $object->app_mode // 'live'
echo $object['mode'] // 'live'
array