3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait T { static $arr = []; public static function a() { self::$arr[] = 'Tx'; static::$arr[] = 'Ty'; } } class C { use T; public static function b() { self::$arr[] = 'Cx'; static::$arr[] = 'Cy'; } } class D { use T; public static function b() { self::$arr[] = 'Dx'; static::$arr[] = 'Dy'; } } T::a(); // make no sense C::a(); C::b(); D::a(); D::b(); assert(C::$arr === ['Tx', 'Ty', 'Cx', 'Cy']); assert(D::$arr === ['Tx', 'Ty', 'Dx', 'Dy']); T::a(); // make no sense assert(C::$arr === ['Tx', 'Ty', 'Cx', 'Cy']); assert(D::$arr === ['Tx', 'Ty', 'Dx', 'Dy']);
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Calling static trait method T::a is deprecated, it should only be called on a class using the trait in /in/ThcGX on line 36 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/ThcGX on line 8 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/ThcGX on line 9 Deprecated: Calling static trait method T::a is deprecated, it should only be called on a class using the trait in /in/ThcGX on line 47 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/ThcGX on line 8 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/ThcGX on line 9
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30

preferences:
237.91 ms | 403 KiB | 372 Q