Skip to content

UndeclaredDynamicProperty ​

warning native on by default PHP ≥ 8.2

Group: Probable bugs

Detect assigning a missing instance property on a resolved PHP 8.2+ class with a complete known hierarchy.

Example ​

php
<?php
class Person {} $p=new Person(); $p->label='Mia';

Reported:

  • line 2: Declare this property before assigning it.

Detection ​

  • Report assigning a missing instance property on a resolved PHP 8.2+ class with a complete known hierarchy.
  • Resolve builtin calls and named arguments before checking the contract. Project-local callees are considered only when their bodies or immutable summaries establish the required facts. The default is enabled, with positive proof required.
  • For flow-dependent conditions, require a reachable source-to-use path with no intervening invalidation. Unknown calls, ambiguous aliases, recursion or analysis-budget exhaustion cannot establish definite facts.

Exceptions (no report) ​

  • stdClass descendants, AllowDynamicProperties classes, classes implementing __set, unknown hierarchies and existing properties are excluded.
  • Unresolved targets, incomplete required facts, suppressed findings and PHP versions lacking the referenced API or language feature produce no report. User declarations shadowing builtin names are not builtin contracts.

Fix ​

No automatic fix: declaring a property changes visibility, serialization and initialization contracts.

PHP versions ​

Available from PHP 8.2. Builtin behavior and argument contracts follow the configured PHP version. Extension-specific calls require resolved extension API symbols; do not treat same-named application functions as extension calls.

Options ​

None. Enable or disable this rule through normal rule configuration.

Configure ​

In custos.json:

json
{
  "rules": {
    "UndeclaredDynamicProperty": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore UndeclaredDynamicProperty

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.