<?php class Json { public function toJSON() { return json_encode(get_object_vars($this)); } } class A extends Json { private $a; function __construct($input = null) { $this->a = $input; } //getter & setter } class B extends Json { private $b; function __construct($input = null) { $this->b = $input; } //getter & setter } $a = (new A("A"))->toJSON(); var_dump($a);
You have javascript disabled. You will not be able to edit any code.