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

__set_state() Method Must Be Static

The magic method __set_state() must be static when declared in a class, starting with PHP 8.0. It used to be an optional keyword.

PHP code

<?php

class X {
    function __set_state() {}
}

?>

Before


After

PHP Fatal error:  Method x::__set_state() must be static

Fatal error: Method x::__set_state() must be static

PHP version change

This behavior changed in 8.0.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat