Access to undeclared static property %s::$%s

Description

This error is reported when reading an undefined static property. The property must be defined before usage, or it yields a Fatal error.

This error is related to static properties: a different error is emitted for non-static properties.

Example

<?php

class X {
     public static $a = 1;
}

$x = new X;
echo X::$a; // OK
echo X::$b;

$name = 'C';
echo X::${$c}; // dynamic properties

?>

Literal Examples

  • Access to undeclared static property X::$staticProperty

Solutions

  • Define the static property in the requested class.

  • Fix the name of the property on that class.

  • Fix the name of the class of the property.

  • Use a non-static property to handle this situation.

  • Use property_exists() or isset() to check if the property exists before using it.

  • Check if the dynamic name of the property is a string, before usage.