"Access to undeclared static property" in PHP — What It Means and How to Fix It

What the PHP error "Access to undeclared static property" means and how to fix it.

Published November 1, 2026

You referenced a static property that the class never declared, or you used the wrong class or name.

What it means and why it happens

Typical causes: typos, calling Class::$prop on a property declared without static, or using self:: inside a child that expects its own declaration.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
Fatal error: Uncaught Error: Access to undeclared static property App\Config::$cache

Practical examples

Code that triggers it

<?php
class Config { public $cache = []; }
echo Config::$cache;   // not static

The fix

<?php
class Config { public static array $cache = []; }
Config::$cache['a'] = 1;
echo Config::$cache['a'];

static vs instance

$c = new Config();
$c->items;       // instance property
Config::$cache;  // static property

Common mistakes

  • Forgetting the static keyword.
  • Using -> for static properties.
  • Typos in property names.

Key takeaways

  • Access to undeclared static property: You referenced a static property that the class never declared, or you used the wrong class or name.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

When use static properties?

For state shared by all instances; prefer instance state or DI otherwise.

How do I find which line caused Access to undeclared static property?

The error message and stack trace show the file and line; start there and work backwards.

More PHP articles