<?php
 abstract class vB_Entity implements JsonSerializable { use vB_Trait_NoSerialize; final public function __get(string $name) : mixed { if ($name[0] == '_') { throw new Exception('disallowed property access'); } if (method_exists($this, $name)) { return $this->$name(); } return $this->$name; } final public function __set(string $name, mixed $value): void { if ($name[0] == '_') { throw new Exception('disallowed property access'); } if (method_exists($this, $name)) { $this->$name($value); } else { $this->$name = $value; } } final public function jsonSerialize(): mixed { return $this->toArray(); } public function toArray() : array { $vars = get_class_vars(static::class); $arr = []; foreach ($vars AS $__key => $__defaultvalue) { $__value = null; if ($__key[0] == '_') { unset($arr[$__key]); $publicname = substr($__key, 1); if ($publicname[0] != '_' AND method_exists($this, $publicname)) { $__value = $this->$publicname(); $__key = $publicname; } else { continue; } } else { $__value = $this->$__key; } if (is_a($__value, 'vB_Entity')) { $__value = $__value->toArray(); } $arr[$__key] = $__value; } return $arr; } final public static function jsonDecode(string $json) : static { $arr = json_decode($json, true); return static::createFromArray($arr); } abstract public static function createFromArray(array $dbrecord) : static; } 