3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait T { static $arr = []; public static function a() { self::$arr[] = 'Tx'; static::$arr[] = 'Ty'; } } T::a(); // make no sense if (TRUE) { 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'; } } } 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Calling static trait method T::a is deprecated, it should only be called on a class using the trait in /in/PUXoR on line 13 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/PUXoR 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/PUXoR 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/PUXoR on line 50 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/PUXoR 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/PUXoR on line 9
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Calling static trait method T::a is deprecated, it should only be called on a class using the trait in /in/PUXoR on line 13 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/PUXoR 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/PUXoR 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/PUXoR on line 50 Deprecated: Accessing static trait property T::$arr is deprecated, it should only be accessed on a class using the trait in /in/PUXoR 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/PUXoR on line 9
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught AssertionError: assert(C::$arr === ['Tx', 'Ty', 'Cx', 'Cy']) in /in/PUXoR:47 Stack trace: #0 /in/PUXoR(47): assert(false, 'assert(C::$arr ...') #1 {main} thrown in /in/PUXoR on line 47
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: assert(): assert(C::$arr === ['Tx', 'Ty', 'Cx', 'Cy']) failed in /in/PUXoR on line 47 Warning: assert(): assert(D::$arr === ['Tx', 'Ty', 'Dx', 'Dy']) failed in /in/PUXoR on line 48 Warning: assert(): assert(C::$arr === ['Tx', 'Ty', 'Cx', 'Cy']) failed in /in/PUXoR on line 51 Warning: assert(): assert(D::$arr === ['Tx', 'Ty', 'Dx', 'Dy']) failed in /in/PUXoR on line 52
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Warning: assert(): Assertion failed in /in/PUXoR on line 47 Warning: assert(): Assertion failed in /in/PUXoR on line 48 Warning: assert(): Assertion failed in /in/PUXoR on line 51 Warning: assert(): Assertion failed in /in/PUXoR on line 52

preferences:
174.93 ms | 402 KiB | 242 Q