PHP code example of drewlabs / php-value

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

    

drewlabs / php-value example snippets


use Drewlabs\PHPValue\ObjectAdapter;

class ValueStub extends ObjectAdapter
{
    protected $__PROPERTIES__ = [
        'name',
        'address',
    ];
}

// Creating instance
$value = new ValueStub([
    'name' => 'Azandrew',
    'address' => '288 Avenue Pia, Lome'
]);

// Imports
use function Drewlabs\PHPValue\Functions\CreateAdapter;

$value =  CreateAdapter([
    // dynamic properties
    'name',
    'address'
]);

// Imports
use function Drewlabs\PHPValue\Functions\CreateAdapter;
$value =  CreateAdapter([
    // dynamic properties
    'name',
    'address'
]);

// This tries to create a deep copy of the object
$value1 = $value->copy([
    'name' => 'Sidoine Azandrew'
]);

// Imports
use function Drewlabs\PHPValue\Functions\CreateAdapter;
$value =  CreateAdapter([
    // dynamic properties
    'name',
    'address'
]);

$result = $value['name']; 
// Same as
$result = $value->name;
// Same as
$result = $value->getAttribute('name');