public function testProperties() { $expect = ['name' => null, 'age' => null]; $class = new PropertyClass(); $this->assertNotEquals($expect, $class->objectVars()); $this->assertEquals($expect, $class->publicVars()); $this->assertEquals($expect, get_object_vars($class)); $this->assertEquals($expect, get_public_properties($class)); $this->assertEquals(['name', 'age'], get_public_properties($class, true)); }
/** * (PHP 5 >= 5.4.0)<br/> * Specify data which should be serialized to JSON * @link http://php.net/manual/en/jsonserializable.jsonserialize.php * @return mixed data which can be serialized by <b>json_encode</b>, * which is a value of any type other than a resource. */ public function jsonSerialize() { // HHVM does not json_encode if (System::isHHVM()) { $values = get_public_properties($this); foreach ($values as $k => $v) { if ($v instanceof \DateTime) { $values[$k] = ['date' => $v->format('Y-m-d H:i:s'), 'timezone_type' => 1, 'timezone' => $v->format('O')]; } } return $values; } return $this; }