PHP code example of pointybeard / property-bag
1. Go to this page and download the library: Download pointybeard/property-bag 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/ */
pointybeard / property-bag example snippets
pointybeard\PropertyBag\Lib;
$p = new Lib\PropertyBag;
$p->fruit = "apple";
$p->animal = new Lib\Property("animal", "lion");
$p->clothing = new Lib\ImmutableProperty("clothing", "hat");
var_dump($p);
$p->fruit = "banana";
var_dump($p->fruit, $p->animal->value);
try{
$p->clothing = "belt";
var_dump($p->clothing);
} catch (Lib\Exceptions\AttemptToChangeImmutablePropertyException $ex) {
print "Oh oh! You can't change Immutable property 'clothing'" . PHP_EOL;
}
print_r($p->toArray());
$p2 = new Lib\PropertyBag;
$p2->username = "barry";
$p2->password = "blahblah";
$p->credentials = $p2;
var_dump(
$p->toArray(),
$p->credentials->value->username,
$p->credentials->value->username->value
);