A content listener must declare public static string $class, matching the extends value in your application's data/listeners.json. Omit it and the front page of the entire community returns a 500 — not just your application's pages.
class Topic extends ContentListenerType
{
public static string $class = 'IPS\forums\Topic'; // REQUIRED
}
Why it is fatal rather than local
ListenerType::getExtendedClass() reads that typed static with no isset() guard, and Event::loadListeners() walks every registered listener on any page that fires an event. One listener missing the property throws "Typed static property must not be accessed before initialization" for every visitor.
Two things that will send you looking in the wrong place
- Disabling the application does not help. Listeners are registered from
data/listeners.jsonregardless ofapp_enabled. Toggling your app off to bisect the problem tells you, convincingly and wrongly, that your app is innocent. - The stack trace names the wrong application. The fatal surfaces inside whichever app owns the front page — commonly
cms/modules/front/pages/page.php— and never mentions the listener at fault. You will spend time on CMS default pages and permissions that are all fine.
Not every listener needs it
Check $requiresClassDeclaration before assuming. IPS's own listeners in cms, blog, gallery, nexus and downloads set it FALSE and derive the class another way, so a checker that flags them is wrong — that is worth knowing before you "fix" core.
Checking every application at once
foreach ( new DirectoryIterator( \IPS\ROOT_PATH . '/applications' ) as $dir )
{
$file = $dir->getPathname() . '/data/listeners.json';
if ( !file_exists( $file ) ) { continue; }
foreach ( json_decode( file_get_contents( $file ), TRUE ) as $key => $definition )
{
$reflect = new ReflectionClass( $definition['classname'] );
$property = $reflect->getProperty( 'class' );
// isInitialized(), not getValue() - reading an uninitialised typed
// static is the very Error you are testing for
if ( !$property->isInitialized() ) { echo "broken: {$key}\n"; }
}
}
Recommended Comments