What the agent does
The agent starts from the request that fails. In musella/php-plots, a single index.php of 294 lines that renders a folder of plot images as a web page, line 115 sorts the folder listing with usort($allfiles, create_function('$a,$b', 'return filemtime($b) - filemtime($a);')), newest file first. The page is deployed by copying the repository into a web folder, as the README says, and every request runs through that line, so on PHP 8 every request answers 500 with PHP Fatal error: Uncaught Error: Call to undefined function create_function() in index.php:115. php -l reports no syntax error, because the call is an ordinary function call to a function that no longer exists; the failure is at run time only.
The PHP manual is explicit about the boundary: create_function was deprecated in 7.2.0 and removed in 8.0.0, and a native anonymous function is the replacement. The rewrite is one line: usort($allfiles, fn($a, $b) => filemtime($b) <=> filemtime($a));, which keeps the order the string-built comparator produced and drops the string evaluation that the old function performed. The agent then serves the directory with PHP's built-in server and requests the page again, and that is where the rest of the job appears.
The next request answers 500 with Uncaught Error: Undefined constant "matchall" at line 172, where the script assigns $matchf = matchall;, a bare word used as a function name, and the same pattern follows on line 177 with preg_match and line 180 with fnmatch. PHP 8 turned a bare constant that does not exist from a warning that resolved to a string into an Error; quoting the three names, 'matchall', 'preg_match' and 'fnmatch', gives call_user_func the strings it always needed. Two more lines, 38 and 44 in get_bookmarks, call split(), one of the ereg functions removed in PHP 7.0 and still a fatal error if a bookmarks file is present; preg_split with the same pattern replaces each. The two reads of $_GET['noplots'] on lines 185 and 272 only warn on PHP 8 with Undefined array key, and !empty($_GET['noplots']) makes them quiet.
With those changes the agent serves the repository's example folder, which holds two PNG plots, and requests the index four ways: with no query, with ?match=cms, with a regular expression ?match=/18.*png/, and with ?noplots=1. Each answers 200, the server log shows no fatal error, and the only remaining log lines are Undefined array key warnings for QUERY_STRING and depth, which the agent lists for the reviewer without changing, since they do not affect the response.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Our PHP site answers 500 with `PHP Fatal error: Uncaught Error: Call to undefined function create_function()` since the server moved to PHP 8. Find every create_function call in the repository and rewrite each as a closure or arrow function with the same parameters and the same return value. Then serve the site with PHP's built-in server and request every page and query variant you can identify from the code, reading the server log after each request. Fix each further PHP 8 fatal error the requests reveal, such as a bare word used as a function name, which PHP 8 reports with \"Undefined constant\", and functions removed in PHP 7 or 8, naming for each the PHP version that removed it according to the PHP manual. Do not change behaviour: a sort must keep its order and a filter must keep its matches. Leave warnings alone but list them. Open a pull request with the diff, the error each request produced before the fix, and the status code and log of each request after it.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- 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.
- 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.
- 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 eight lines of index.php: the usort comparator on line 115, the three bare function names on lines 172, 177 and 180, the two split calls on lines 38 and 44, and the two $_GET['noplots'] reads. The description lists the errors in the order the requests surfaced them, each with its line, the PHP release that made it fatal as the manual states it, and the replacement. Below that is a table of the four requests after the change with their status codes, and the server log with no fatal lines.
The reviewer checks what a diff cannot show: that the arrow function sorts newest first exactly as the string comparator did, that each quoted name is the function the script meant, so ?match= still chooses preg_match for a pattern wrapped in slashes and fnmatch for anything else, and that the preg_split patterns match the same separators split matched, including the && with optional spaces around it in the bookmarks file format.
What the run does not prove is the production web server. The built-in server runs the script from the repository checkout, and this script resolves the folder it lists from REQUEST_URI and DOCUMENT_ROOT, so the image list under Apache or nginx depends on how the site is mounted; the pull request says that the request paths answered 200 in the sandbox and leaves the mounted listing to the reviewer.
Run it on every PHP upgrade on a shared web host
Sites like this one live on institutional web servers, and the error arrives the morning after the host moves PHP, as a 500 on every page and a line in the server's error log. A log watcher or uptime check that can send a custom header can post the log line straight to a Rush webhook trigger's URL with the trigger's secret in Authorization: Bearer; one that cannot, such as a monitoring service that signs its own deliveries, goes through a small handler on your server that forwards it. The log text lands after the saved prompt as the event, so the prompt tells the agent which file and line to open first.
Send an Idempotency-Key header to the trigger's URL built from the host name and the error text, so a page that fails on every request starts one run and not one per hit, and keep the automation's runs per hour low for the same reason.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
php -l passes on this file, so nothing short of running it under PHP 8 finds the problem, and the next problem hides behind the first: the bare constant on line 172 only appears once create_function is fixed, and the split calls only when a bookmarks file exists. A Rush sandbox installs PHP 8, serves the checkout with the built-in server, and requests each variant in turn, so each fatal error is found by a request rather than by reading, and the log of every request is kept.
The result is a pull request a reviewer can check against the manual, not against a hunch. Each removed function is named with the release that removed it, each request is listed with the status it answered, and the one place the sandbox cannot stand in for the real server, the mounted folder, is called out instead of glossed.
Frequently asked questions
Which PHP version removed create_function?
PHP 8.0.0; it had been deprecated since 7.2.0, as the manual's page for the function states. The manual's replacement is a native anonymous function, and for a two-argument comparator an arrow function with the spaceship operator is the shortest form that keeps the order.
Why does php -l say there are no syntax errors?
Because the file is valid PHP; it calls a function that is not defined, which is only known at run time. The same holds for split() and for a bare word used as a function name. The agent finds these by serving the site and requesting pages, with the server log open, rather than by linting.
What is the 'Undefined constant' error after the first fix?
A bare word such as $matchf = matchall;. Before PHP 8 a constant that did not exist became the string 'matchall' with a warning, so call_user_func worked; PHP 8 throws an Error for it, as the migration guide lists. Quoting the name restores exactly the string the code relied on.
Will the arrow function sort the same way?
Yes. The old comparator returned filemtime($b) - filemtime($a), newest first; filemtime($b) <=> filemtime($a) returns the same sign for every pair, and usort only reads the sign. The pull request shows the sorted listing from the served page.
Does the agent fix the warnings too?
Only where a warning sits on the same line as a fatal change, such as the $_GET['noplots'] reads. The remaining Undefined array key warnings for QUERY_STRING and depth are listed in the pull request with their lines and left for a separate change, since they do not change what the page returns.