0

I want to move from PHP 5.4 to PHP 7... So I checked compatibility between PHP 5 and PHP 7. I have found that I function my code uses is deprecated: get_magi_quotes_gpc_runtime().

What would be the alternative since the documentation does not recommend any?

Noah Boegli
  • 750
  • 1
  • 7
  • 24
Sumathraj
  • 31
  • 1
  • 3
  • Please provide the error given. The code as is seems OK. The context matters here. – Mulli Apr 08 '20 at 08:07
  • @Mulli He want to know what to replace [`get_magic_quotes_runtime`](https://www.php.net/manual/en/function.get-magic-quotes-gpc.php) with in PHP 7 as it has been deprecated and the document does not state what to replace it with. There is no need for him to post an error since it's documented. – Noah Boegli Apr 08 '20 at 08:09
  • 1
    You replace it with `$magic_quotes = false;` because it's always false past PHP 5.4. The conversation at https://stackoverflow.com/questions/61054418/php-7-4-deprecated-get-magic-quotes-gpc-function-alternative might be relevant here too – apokryfos Apr 08 '20 at 08:09

2 Answers2

0

the php7 equivalent is:

$magic_quotes=false;

magic_quotes is no longer supported. it was never a good idea, and should be avoided whenever possible. still, since magic_quotes was basically just running addslashes() on everything in $_GET / $_POST / $_COOKIE, porting it to modern php is not a difficult task, and you can find magic_quotes ported to modern PHP in the wordpress framework here: https://github.com/WordPress/WordPress/blob/38676936bac7963a62e23e0d2ec260a1ae9731ea/wp-includes/formatting.php#L5453

/**
 * Add slashes to a string or array of strings.
 *
 * This should be used when preparing data for core API that expects slashed data.
 * This should not be used to escape data going directly into an SQL query.
 *
 * @since 3.6.0
 *
 * @param string|array $value String or array of strings to slash.
 * @return string|array Slashed $value
 */
function wp_slash( $value ) {
    if ( is_array( $value ) ) {
        foreach ( $value as $k => $v ) {
            if ( is_array( $v ) ) {
                $value[ $k ] = wp_slash( $v );
            } else {
                $value[ $k ] = addslashes( $v );
            }
        }
    } else {
        $value = addslashes( $value );
    }

    return $value;
}

shrugs

hanshenrik
  • 19,904
  • 4
  • 43
  • 89
0

According to PHP manual:

$magic_quotes = false; 
Mulli
  • 1,598
  • 2
  • 22
  • 39