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

Storage Of Static Properties Trait

Static properties defined in a trait used to be merged with any existing static property in a parent class. Since PHP 8.3, the static property is directly related to the importing class, and is made distinct from any pre-existing static class.

PHP code

<?php

trait T {
    static $T = 1;
}

class X {
    static $T = 1;

    function goo() {
        echo self::$T;
    }

}

class Y extends X {
    use t;
    
    function foo() {
        self::$T = 2;
        echo self::$T;
        self::goo();
    }
    
}

(new y)->foo();

?>

Before

2

After

1

PHP version change

This behavior changed in 8.3.

Extension

© 2023-2026, Damien Seguy - Exakat