_set( $data ); } /** * Returns objects properties as array * * @return array */ public function to_array() { return (array) $this->_get_data(); } /** * Returns objects properties as json * * @return false|mixed|string|void */ public function to_json() { return json_encode( $this->_get_data() ); } /** * @param $property * * @return bool */ public function get_property( $property ) { if ( ! isset( $this->{$property} ) ) { return false; } return $this->{$property}; } /** * Returns all object accessible non-static properties in this scope * * @return array */ private function _get_data() { return get_object_vars( $this ); } /** * @param $data */ private function _set( $data ) { foreach ( $data as $key => $value ) { if ( property_exists( $this, $key ) ) { $this->{$key} = $value; } } if ( $this->title ) { $this->id = md5( $this->title ); } $this->date = date( 'jS F Y' ); $this->read = 0; } }