What the agent does
Since PHP 8.2, assigning to a property that a class never declared prints Deprecated: Creation of dynamic property Foo::$bar is deprecated, and the PHP project has said the same assignment will become an error in a later major version. The notice names one property at a time, on the code path that happened to run, so a codebase clears it in one place and meets it again a week later somewhere else. An agent approaches it the other way round: read each class, list every $this->name it assigns, subtract the declared properties, and fix the whole difference at once.
dapphp/securimage, a captcha library whose composer.json still allows "php": ">=5.4", shows why the list beats the log. An open issue on that repository reports two notices on PHP 8.2, for Securimage::$code_entered and Securimage::$correct_code; both are assigned in check() and neither is declared. Reading the class finds two more that the reporter's page load never reached: $this->namespace, assigned in setNamespace(), and $this->gdnoisecolor, assigned in allocateColors() while the image is being drawn. That last one is the costly one. With display_errors on, a notice printed during image generation lands in a response that is supposed to be image bytes.
For each of the four, the agent adds a declaration beside the class's existing properties, with a default that matches how the code reads the value before it is set. It writes plain untyped declarations, because typed properties need PHP 7.4 and this library's stated floor is far below that. Then it handles the case a declaration cannot solve. The Securimage constructor loops over its $options array and runs $this->$prop = $val for each key, so an option name with a typo, or one from a newer version's documentation, becomes a dynamic property at run time. The agent does not guess at intent here. It reports the loop and offers the two honest choices: ignore and log option keys that match no declared property, or mark the class #[\AllowDynamicProperties] and keep accepting anything.
Verification is a script, not a page refresh. The agent installs PHP 8.2 or later in its sandbox, sets error_reporting(E_ALL), and registers an error handler that turns any deprecation into an exception. It then calls each public method that the list touched, such as check() and setNamespace(), and the image path where the GD extension is available. A run with no exception means no dynamic property was created on those paths. It runs the same script against the unmodified code first, so the pull request can show the four failures and then their absence. The repository's README states that the library is no longer maintained, and the agent says so in its report, since a team that vendors it will be carrying this patch themselves.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This codebase prints \"Deprecated: Creation of dynamic property ... is deprecated\" on PHP 8.2 and later. Do not fix only the properties named in logs. For every class in the repository (skip vendor/ and generated code), build a list: each property assigned through $this->name, self or a typed variable of that class, minus the properties the class or its parents declare. Also find every place that assigns a property whose name is a variable ($this->$key = ..., $obj->{$name} = ...) and every class that already defines __set. For each undeclared property with a fixed name, add a declaration next to the class's other properties, with visibility and a default that match how the code uses it, and no type declaration unless composer.json requires PHP 7.4 or later. Do not rename anything and do not change behaviour. For variable-name assignments, do not guess: if the keys come from a fixed set, declare them; otherwise leave the code as it is, list the location, and propose either validating keys against declared properties or adding #[\\AllowDynamicProperties] to that class, with the trade-off of each. Use #[\\AllowDynamicProperties] on your own only for classes that are plain data bags by design, and say which. Then prove it: install PHP 8.2 or newer with the extensions composer.json requires, write a script that sets error_reporting(E_ALL), installs an error handler that throws on E_DEPRECATED, and exercises the public methods of every class you changed. Run it before and after your change and include both outputs. Run the project's test suite if it has one. Open a pull request listing every property you declared, by class, and every location you left for a decision.",
"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 whose diff is mostly added property declarations, grouped by class, with no change to method bodies. The description opens with the inventory: class, property, the method that first assigns it, and whether a log or issue had already reported it. For a library like the one above, that table has four rows where the bug report had two.
Below the inventory are the locations left alone on purpose, each with a recommendation. Variable-name assignments are the main entry, and the description spells out what each option changes for callers: validation makes an unknown option a visible mistake, while the attribute keeps old behaviour and hides typos. The verification script is committed under the test directory or attached to the session, with its output before and after.
A reviewer checks two things. The defaults: a declared property now exists with its default from construction, so code that tested isset($this->name) or property_exists() to learn whether a method had run may read differently, and the agent flags each such read it found. And the scope: nothing under vendor/ is edited, so notices raised inside dependencies are listed with the package name and left to an upgrade.
Run it on every Linear issue labelled php-8.2
A PHP version upgrade is usually tracked as a set of tickets, one per service or package, and this job fits one ticket each. Add an automation to the Project for the repository, with the prompt above and a linear trigger on linear.issue.labeled whose labels include the label your team applies. When someone in your Rush org adds that label, a run starts with the issue appended after the prompt as event text.
The trigger needs a Linear connection for the member the automation runs as, made in the console under Settings → Connections. Label changes made by an app integration do not fire it, so a bulk relabel through another tool starts nothing; a person applying the label does.
The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.
Why run it on Rush?
The laptop version of this fix is reactive: load a page, read the notice, declare one property, reload. It finds only what that page exercises. The agent reads every class regardless of whether today's traffic reaches it, and then runs the affected methods under a PHP version where each remaining dynamic assignment throws. Both halves are recorded, so the inventory in the pull request is backed by a script anyone can run again.
It also needs a PHP that the team may not have installed yet. The point of the work is to be ready before production moves to 8.2 or later, which means the developer's machine is often still on the old version. A sandbox with the new interpreter and the required extensions, created for the run and discarded after it, removes that obstacle without changing anyone's local setup.
Frequently asked questions
Can I just add #[\AllowDynamicProperties] to every class?
It silences the notice, and on PHP versions before 8.0 the line is read as a comment, so it is safe for old runtimes. It also keeps the behaviour the deprecation exists to remove: a mistyped property name creates a new property instead of failing. The agent reserves it for classes that hold arbitrary keys by design and declares properties everywhere else.
Why not extend stdClass?
Classes that extend stdClass may still create dynamic properties without a notice, so it works. It changes the class hierarchy, though, which can affect instanceof checks and serialisation. The attribute has the same effect with no change to inheritance, so the agent prefers it when dynamic properties are truly wanted.
The notices come from a package in vendor/. What does the agent do?
It does not edit vendored code. It reports the package and version, checks whether a newer release declares the properties, and raises the constraint in composer.json when the project's tests pass with it. Where no fixed release exists, it says so and names the classes involved.
Does declaring a property change behaviour?
For reads and writes, no. The differences are at the edges: property_exists() is true from construction, a foreach over the object includes the property earlier, and serialised output includes it with its default. The agent searches for those uses in the classes it changed and lists any it finds.
Is it only a notice, or does it break anything today?
On 8.2 and later 8.x releases it is a deprecation and execution continues. It breaks things indirectly: an error handler or test runner configured to fail on deprecations will stop, and a notice printed into a JSON or image response corrupts it. Fixing it now also removes the work from the next major upgrade.