PHP code still calls eregi(), which was deprecated and then removed
Deprecated: Function eregi() is deprecated inShort answer
eregi() belongs to the ereg extension, which PHP deprecated in 5.3 and removed in 7.0. On a current PHP the call cannot work, so port it. Replace each call with preg_match(), put the pattern between delimiters and add the i modifier for case-insensitive matching, and check the result with ===.
Fix it fast
1Find out which cause you have
List every call to the ereg family in the project, not only the one in the error. The whole extension is gone, so the next call will fail the same way.
grep -rnwE "ereg|eregi|ereg_replace" --include=*.php .2Match what you see, then jump to its fix
What does the error look like?
Deprecated: Function eregi() is deprecated ineregi() is deprecated
Cause 1 of 2
A case-insensitive check still uses eregi()
1Check
The PHP 7.0 RFC for removing deprecated functionality lists ext/ereg as deprecated since PHP 5.3 and as removed, implemented in PHP 7.0. Read the call and note the pattern and the string it is matched against.
grep -rn "eregi(" --include=*.php .2Fix
Use preg_match() from the PCRE extension, as the RFC says. The manual's example shows the i after the closing delimiter making the search case-insensitive.
<?php
// before (removed)
// if (eregi("php", $subject)) { ... }
// after
if (preg_match('/php/i', $subject) === 1) {
// matched
}3Verify
Check the file for syntax errors, then run the page that used to warn and confirm it matches the same strings as before.
php -l path/to/file.phpConfirmed by php.net
Cause 2 of 2
Other functions of the same extension are left in the code
1Check
The RFC removes ext/ereg as a whole extension, not one function. Every function it provided fails the same way, so search for all of them before you deploy.
grep -rnwE "ereg|ereg_replace" --include=*.php .2Fix
Port each of them to the PCRE extension, which the RFC names as the replacement. If you cannot port a third-party plugin, take a release of it that supports your PHP version.
<?php
// ereg() match test, ported
if (preg_match('/^[a-z]+$/', $name) === 1) {
// name is letters only
}3Verify
Repeat the search from the first step. It should return no hits in your own code.
grep -rnwE "ereg|eregi|ereg_replace" --include=*.php .Confirmed by wiki.php.net
How do I stop it coming back?
- Run the code on the PHP version you will deploy, with error reporting on, before the upgrade.
- Test the return value of preg_match() with ===, because the manual says it returns 1, 0, or false on failure.
- Keep themes and plugins on releases that support your PHP version, instead of patching their code by hand.
- Add a search for the old function names to your CI, so they cannot come back.
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