public function serialize($toJson = true)
    {
        $data = [];

        $getters = $this->classGetters(get_class($this));
        foreach ($getters as $method) {
            $property = $this->propertyName($method);
            $value = $this->$method();

            if (is_float($value)) {
                $value = sprintf("%01.2f", $value);
            } elseif (is_object($value)) {
                $value = $value->serialize(false);
            }

            if ($value !== null) {
                $data[$property] = $value;
            }
        }

        if ($toJson === true) {
            return json_encode($data);
        }

        return $data;
    }
public function serialize($toJson = true)
    {
        $data = [];

        $getters = $this->classGetters(get_class($this));
        foreach ($getters as $method) {
            $property = $this->propertyName($method);
            $value = $this->$method();

            if (is_float($value)) {
                $value = sprintf("%01.2f", $value);
            } elseif (is_object($value)) {
                $value = $value->serialize(false);
            }

            if ($value !== null) {
                $data[$property] = $value;
            }
        }

        if ($toJson === true) {
            return json_encode($data);
        }

        return $data;
    }
public function serialize ( $ toJson = true ) { $ data = [ ] ; $ getters = $ this -> classGetters ( get_class ( $ this ) ) ; foreach ( $ getters as $ method ) { $ property = $ this -> propertyName ( $ method ) ; $ value = $ this -> $ method ( ) ; if ( is_float ( $ value ) ) { $ value = sprintf ( "%01.2f" , $ value ) ; } elseif ( is_object ( $ value ) ) { $ value = $ value -> serialize ( false ) ; } if ( $ value !== null ) { $ data [ $ property ] = $ value ; } } if ( $ toJson === true ) { return json_encode ( $ data ) ; } return $ data ; }
Serializes result object to json object
@param boolean $toJson encode result to json
@return array|object
Serializes result object to json object