<?php
namespace ModulesAbstract\ElectronicInvoice; class StdClassExtended extends \stdClass { public function asJSON($jsonOptions = 0) { return json_encode($this, $jsonOptions); } public function __toString() { if (!get_object_vars($this)) { return ''; } return $this->asJSON(); } public function &add(string $name, mixed $value = NULL) { if ($value===null) { $value = new self(); } if (property_exists($this, $name) && !is_array($this->{$name})) { $this->{$name} = [ $this->{$name} ]; $this->{$name}[] = $value; return end($this->{$name}); } else { $this->{$name} = $value; return $this->{$name}; } } public function get($name) { return (property_exists($this, $name) ? $this->{$name} : null); } } 