Devsense PHP Tools shows an undefined property warning in VS Code
A squiggle under a property name with the message that the property is unknown or undefinedShort answer
The extension reports a property it cannot find on the class. First decide if it is a real gap: declare the property, or add an @property tag when __get or __set provides it. If the code is intentional, hide only that diagnostic code with .editorconfig, php.problems.exclude, or an @suppress tag on the class, not all problems.
Fix it fast
1Find out which cause you have
Open the Problems panel and read the code (the docs list the unknown-property warning as PHP0416, Unknown field use). Use the code your panel shows in every setting below.
View > Problems (Ctrl+Shift+M)2Match what you see, then jump to its fix
- 1
The warning points at $this->something or $obj->something that no class body declaresThe property is not declared on the classFix - 2
The class has magic __get or __set, and the extension reports a hint about a magic propertyThe property comes from __get or __set but is not annotatedFix - 3
The code is correct for your design, and you only want this warning silentThe pattern is intentional and you want one diagnostic hiddenFix - 4
Only one legacy class needs the exceptionYou want it silent for one class or function onlyFix
- 1
What does the error look like?
A squiggle under a property name with the message that the property is unknown or undefinedThe same warning listed in the VS Code Problems panel with a PHP code
Cause 1 of 4
The property is not declared on the class
1Check
The diagnostic means the property is unknown to the analyzer. On PHP 8.2 and later, creating such a property at runtime is also deprecated, unless the class opts in or is stdClass.
grep -n "public \$\|private \$\|protected \$" src/Order.php2Fix
Declare the property. The PHP manual lists declaring it as the preferred fix for dynamic properties. #[AllowDynamicProperties] on the class is the opt-in for code you cannot change.
class Order
{
public ?string $note = null;
}3Verify
The squiggle disappears after the extension re-analyses the file.
php -l src/Order.phpConfirmed by php.net
Cause 2 of 4
The property comes from __get or __set but is not annotated
1Check
The extension's diagnostics list says a property handled by magic __get or __set may be unintentional when it is not declared with an @property annotation while other properties are.
grep -n "__get\|__set\|@property" src/Model.php2Fix
Describe the magic properties in the class docblock.
/**
* @property string $title
* @property int $views
*/
class Model
{
public function __get($name) { /* ... */ }
}3Verify
The hint no longer appears for those names.
php -l src/Model.phpConfirmed by docs.devsense.com
Cause 3 of 4
The pattern is intentional and you want one diagnostic hidden
1Check
The extension can hide problems per diagnostic code. A rule with an error code beats a general php_diagnostic rule.
cat .editorconfig 2>/dev/null2Fix
Add a code rule to .editorconfig (false, off or none hides it), or exclude the code in VS Code's settings.json. Use the code from your Problems panel.
# .editorconfig
[*.php]
php_diagnostic_php0416 = false
// settings.json (an array hides only the listed codes in that path)
"php.problems.exclude": {
"src/legacy/": [416]
}3Verify
Reload the window and confirm the warning is gone for those files only.
Developer: Reload Window (Command Palette)Confirmed by docs.devsense.com
Cause 4 of 4
You want it silent for one class or function only
1Check
A docblock tag suppresses problems for the function or class it is attached to.
grep -n "@suppress" -r src | head2Fix
Add @suppress with the code to that docblock. Several codes can be separated by a comma or a space.
/**
* @suppress PHP0416
*/
class LegacyReport
{
}3Verify
The warning is gone inside that class and still shows elsewhere.
Developer: Reload Window (Command Palette)Confirmed by docs.devsense.com
How do I stop it coming back?
- Declare properties on the class; it also keeps your code clean on PHP 8.2 and later.
- Hide single codes in a small path, not everything with true.
- Commit .editorconfig so the team sees the same Problems list.
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
Deprecated: Creation of dynamic property in PHP 8.2 and later
Deprecated: Creation of dynamic property Foo::$bar is deprecated
PHP 8.2 deprecates assigning to a property the class never declared; PHP 9.0 will make it an Error.
3 causes, each with a fixBack 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 fix