public static function objectToArray($source): array
    {
        $result = [];

        if (is_array($source)) {
            return $source;
        }

        if (!is_object($source)) {
            return $result;
        }

        $json = json_encode($source);
        if ($json === false) {
            return $result;
        }

        $array = json_decode($json, true);
        if ($array === null) {
            return $result;
        }
        $result = $array;

        return $result;
    }
public static function objectToArray($source): array
    {
        $result = [];

        if (is_array($source)) {
            return $source;
        }

        if (!is_object($source)) {
            return $result;
        }

        $json = json_encode($source);
        if ($json === false) {
            return $result;
        }

        $array = json_decode($json, true);
        if ($array === null) {
            return $result;
        }
        $result = $array;

        return $result;
    }
public static function objectToArray ( $ source ) : array { $ result = [ ] ; if ( is_array ( $ source ) ) { return $ source ; } if ( ! is_object ( $ source ) ) { return $ result ; } $ json = json_encode ( $ source ) ; if ( $ json === false ) { return $ result ; } $ array = json_decode ( $ json , true ) ; if ( $ array === null ) { return $ result ; } $ result = $ array ; return $ result ; }
Convert an object to associative array

NOTE: in case of any issues during the conversion, this
method will return an empty array and NOT throw any
exceptions.

@param mixed $source Object to convert
@return mixed[]
Convert an object to associative array