Old PHP code calls get_magic_quotes_gpc(), which no longer exists
Deprecated: Function get_magic_quotes_gpc() is deprecatedShort answer
get_magic_quotes_gpc() was deprecated in PHP 7.4 and removed in PHP 8.0, so old code that calls it throws a fatal undefined-function error on PHP 8. The function always returned false anyway. Delete the check and its stripslashes() branch, and protect database queries with prepared statements instead of manual escaping.
Fix it fast
1Find out which cause you have
Find every place the old function is used, so you can see which branch each one guards.
grep -rn "get_magic_quotes" --include=*.php .2Match what you see, then jump to its fix
What does the error look like?
Deprecated: Function get_magic_quotes_gpc() is deprecatedFatal error: Uncaught Error: Call to undefined function get_magic_quotes_gpc()
Cause 1 of 2
A guard around stripslashes() that cannot run any more
1Check
The manual says the function was deprecated in 7.4.0, removed in 8.0.0, and always returns false. So the branch it guards is dead code.
grep -rn -B1 -A3 "get_magic_quotes_gpc" --include=*.php .2Fix
Remove the check and the stripslashes() call it guards. Do not wrap it in function_exists(): the value would be false anyway.
// before
if (get_magic_quotes_gpc()) {
$name = stripslashes($_POST['name']);
}
// after
$name = $_POST['name'];3Verify
Search again: no call should be left, then reload the page that crashed.
grep -rn "get_magic_quotes" --include=*.php .Confirmed by php.net
Cause 2 of 2
The code relied on automatic slashes to keep SQL safe
1Check
Magic quotes were never a safe way to build queries. Look for variables concatenated into SQL.
grep -rn "mysqli_query\|->query(" --include=*.php .2Fix
Use a prepared statement. The mysqli manual says bound variables are sent to the server separately from the query, so they cannot interfere with it and need no escaping.
$stmt = $mysqli->prepare("INSERT INTO test(id, label) VALUES (?, ?)");
$stmt->bind_param("is", $id, $label);
$stmt->execute();3Verify
Submit a value that contains a quote character such as O'Brien and confirm it is stored unchanged.
php -l path/to/file.php # syntax check only; then test the form by handConfirmed by php.net
How do I stop it coming back?
- Run old code through php -l and a static analyser before upgrading PHP.
- Check the PHP manual's deprecated-function notes before every major PHP upgrade.
- Escape for output (htmlspecialchars) where text goes into HTML, not on input.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Apache returns 403 when a URL contains %3F
a request like /page%3Fname=test is refused while /page?name=test works
Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.
2 causes, each with a fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix