How to replace get_magic_quotes_runtime() in PHP7.4

Viewed 7746

The function get_magic_quotes_runtime is deprecated in PHP 7.4 as per documantation.

This function has been DEPRECATED as of PHP 7.4.0. Relying on this function is highly discouraged.

How to replace it with a valid code with the same functionality?

A particular example PunBB v1.4.5, file: common.php line 18:

// Turn off magic_quotes_runtime
if (get_magic_quotes_runtime()) {
    @ini_set('magic_quotes_runtime', false);
}
3 Answers

Well it is a reference to magic_quotes_runtime which is itself deprecated as of PHP 5.3 and REMOVED in PHP 5.4 so you have no need to use get_magic_quotes_runtime in PHP 7.4

So you can simply update your code accordingly:

/***
 * Turn off magic_quotes_runtime
 * this function serves no purpose
if (get_magic_quotes_runtime()) {
    @ini_set('magic_quotes_runtime', false);
}
***/

Edit: This is just an example, you can simply delete your shown code ;-)

The proper way to replace it is to not use. You can do that by

if(version_compare(PHP_VERSION, '7.4.0', '<') && get_magic_quotes_runtime()) {
    @set_magic_quotes_runtime(0);
}

magic_quotes_runtime always returns false as of PHP 5.4.0, has been DEPRECATED as of PHP 7.4.0, and REMOVED as of PHP 8.0.0. The proper way is to not use it in the newest versions:

// get_magic_quotes_runtime
$mqr = false;
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  $mqr = get_magic_quotes_runtime();
}

...

// set_magic_quotes_runtime
$mqr = true;
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  set_magic_quotes_runtime($mqr); 
}
Related