# Fix `Call to undefined function get_magic_quotes_gpc()` When a PHP App Lands on PHP 8

Yes. An agent removes the magic-quotes check without changing what the app does to its input, and serves the app on PHP 8 to prove the page renders.

[Run this on Rush](https://cloud.getrush.ai/run/fix-get-magic-quotes-gpc-removed/php/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the file the error names and the image the project ships, because the call is usually one old guard and the project's own PHP version explains why nobody saw it. In an app like thibaud-rohmer/PhotoShow, `index.php` line 74 reads `if (!get_magic_quotes_gpc()){` and the three lines inside it pass `$_POST`, `$_COOKIE` and `$_GET` through `protect_user_send_var`, a function defined a few lines above that maps `addslashes` over arrays. `docker/Dockerfile` starts from `alpine:3.10.1` and installs `php7-fpm`, `php7-gd` and the other `php7-*` packages, so the project's own container never ran PHP 8.

It reproduces the failure on the PHP that hosts run now. On PHP 8.2 `php -r 'get_magic_quotes_gpc();'` prints `PHP Fatal error: Uncaught Error: Call to undefined function get_magic_quotes_gpc()`, and `function_exists('get_magic_quotes_gpc')` is false. Serving the repository with `php -S` and requesting `index.php` shows how users see it: PhotoShow's own error handler catches the `Error` and renders `<div class='exception'>Call to undefined function get_magic_quotes_gpc()</div>` with an HTTP 200, so a monitor that checks status codes never notices.

The fix keeps the app's behaviour. Magic quotes were removed from PHP in 5.4, so on every PHP the project has run in years `get_magic_quotes_gpc()` returned false and the three `protect_user_send_var` calls always ran. The agent deletes the `if` and keeps the three calls unconditional, which is exactly what the old code did on PHP 5.4 through 7.4. `php -l` over the project's own files reports no syntax errors, and a search of the project's code outside the vendored `src/` directory finds no `each()`, `create_function()`, `ereg()`, `split()` or `mysql_*` call to trip on next.

The vendored phpThumb copy under `src/phpthumb` also calls `@get_magic_quotes_gpc()`, on line 3922 of `phpthumb.class.php`, inside its debug dump, which runs only when `config_disable_debug` is turned off; the class ships with it set to true. The `@` does not silence an `Error` on PHP 8, so the agent leaves the vendored file alone and records the line in the pull request as what would break if debug output were ever enabled. After the change, the served `index.php` answers 200 with `<title>PhotoShow</title>` and the gallery's normal page.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Our PHP app shows `Call to undefined function get_magic_quotes_gpc()` after the host moved to PHP 8. Find every call to it, read the code around each one and the PHP version the project's own Dockerfile installs, and serve the app on PHP 8 to show what the page returns now. Remove the magic-quotes guard in our own code so the input handling stays exactly what it was on PHP 5.4 and later, run php -l over our files, and search our code for other functions PHP 8 removed. Leave vendored libraries alone but list any call they make. Serve the app again and open a pull request quoting the response before and after.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that changes `index.php` only: the `if (!get_magic_quotes_gpc())` line and its closing brace are gone, and the three `protect_user_send_var` assignments stay, now unconditional. The description quotes the fatal error from the PHP 8 command line, the HTML the app's error handler returned before, and the `<title>PhotoShow</title>` response after.

A reviewer checks that `addslashes` is still applied to the same three superglobals, that no vendored file under `src/` changed, and that the Dockerfile still installs PHP 7, which the pull request notes but does not change.

The description lists the one vendored call in phpThumb's debug dump with its line and the setting that keeps it unreachable, so the team knows what breaks if they ever turn that debug mode on.

## Run it on every PHP version change on a host

A host upgrade breaks every old app at once, so the useful unit is each PHP repository the org still runs. Your server sends this request once per repository, each with its own UUID as `request_id` so a retry returns the run it already started, and reads the results from the key's `run.completed` webhooks. A key starts at most `max_concurrent` runs at once and queues the rest.

A Grafana alert on 200 responses that contain the string `exception` can call a Rush `webhook` trigger directly, since a Grafana contact point sends an `Authorization: Bearer` header with the trigger's secret; the alert payload reaches the agent as data after the prompt.

## Why run it on Rush?

The app hides this failure behind a 200 page, so proof means serving it, not reading it. In a Rush sandbox the agent installs PHP 8.2, starts the built-in server against the checkout, requests the page before and after, and keeps both responses with the run, so the pull request shows what a user saw and what they see now.

The right fix is to remove a guard without changing input handling, and the argument for that rests on what the old code did on the PHP versions the project supported. The agent reads the Dockerfile for that history, searches for the other removed functions so the next fatal error is already known, and leaves vendored code untouched with the one risky line named.

## Frequently asked questions

### Why not replace the call with a stub that returns false?

Because the guard has done nothing since PHP 5.4 removed magic quotes: the function returned false, so the three `addslashes` calls always ran. Deleting the condition keeps that behaviour with less code, and a stub would keep a dead concept alive.

### Why does the monitor show the site as up?

PhotoShow's error handler renders the exception inside the page and answers HTTP 200. The agent reproduces that with `php -S` and quotes the response, so a reviewer sees why status checks missed it.

### Does the vendored phpThumb need patching?

Not for this failure. Its only call sits in a debug dump that runs when `config_disable_debug` is false, and the class ships with it true. The pull request records the line so turning debug on is a known risk.

### What else from PHP 8 would break this app?

The agent searches the project's own code for `each()`, `create_function()`, `ereg()`, `split()` and `mysql_*` calls and runs `php -l` on every file. In PhotoShow's own code it finds none, and says so; if it did, each would be its own fix.

## More PHP jobs

- [Fix Call to Undefined Function mysql_connect() on PHP 7 and PHP 8](https://getrush.ai/run/fix-mysql-connect-function-removed/php/)
- [Fix "Passing null to parameter of type string is deprecated" on PHP 8.1 and later](https://getrush.ai/run/fix-passing-null-to-parameter-deprecated/php/)
- [Fix "Return type should either be compatible with ArrayAccess::offsetGet" Deprecations on PHP 8.1](https://getrush.ai/run/fix-return-type-will-change-deprecation/php/)

## More jobs like this: Fix a bug from an alert

- [Fix "TypeError: glob is not a function" after upgrading the glob package](https://getrush.ai/run/fix-glob-is-not-a-function/glob/)
- [Fix "Global built-in functions are deprecated and will be removed in Dart Sass 3.0.0" warnings](https://getrush.ai/run/fix-global-built-in-functions-are-deprecated-warning/sass/)
- [Fix "go get: installing executables with 'go get' in module mode is deprecated" in a mockgen Makefile](https://getrush.ai/run/fix-go-get-installing-executables-deprecated/gomock/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
