Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

get_called_class() Cannot Be Called Outside A Class

get_called_class() generated a warning when called outside a class or an enumeration. Since PHP 8.0, it is a fatal error.

PHP code

<?php

var_dump(get_called_class());

?>

Before

PHP Warning:  get_called_class() called from outside a class

Warning: get_called_class() called from outside a class
bool(false)

After

PHP Fatal error:  Uncaught Error: get_called_class() must be called from within a class

Fatal error: Uncaught Error: get_called_class() must be called from within a class

PHP version change

This behavior was deprecated in 7.0.

This behavior changed in 8.0.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat