public static function copy( $input, bool $deep = true ) {

    if( !static::is( $input ) ) return $input;
    else {

      if( is_array( $input ) ) {

        $result = [];
        foreach( $input as $k => $e ) {
          $result[ $k ] = $deep ? static::copy( $e, $deep ) : $e;
        }

      } else {

        // handle (and detect non-)cloneable object (private __clone method is considered non-cloneable)
        if( method_exists( $input, '__clone' ) && !is_callable( [ $input, '__clone' ] ) ) $result = $input;
        else if( !( $input instanceof \StdClass ) ) $result = clone $input;
        else {

          $result = new \stdClass();
          foreach( $input as $k => $e ) {
            $result->{$k} = $deep ? static::copy( $e, $deep ) : $e;
          }
        }
      }

      return $result ?? $input;
    }
  }