3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Category { public $foo = [1, 2, 3]; public function getCategories($type) { return $this->foo; } } class ChildCategory extends Category { } // This works fine $categories = (new ChildCategory())->getCategories('xxx'); var_dump($categories); // Fatal error: Uncaught Error: Using $this when not in object context $categories = Category::getCategories('xxx'); var_dump($categories);
Output for 8.1.28 - 8.1.33, 8.2.15 - 8.2.29, 8.3.2 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Fatal error: Uncaught Error: Non-static method Category::getCategories() cannot be called statically in /in/eMj68:22 Stack trace: #0 {main} thrown in /in/eMj68 on line 22
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 7.0.33
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Deprecated: Non-static method Category::getCategories() should not be called statically in /in/eMj68 on line 22 Fatal error: Uncaught Error: Using $this when not in object context in /in/eMj68:9 Stack trace: #0 /in/eMj68(22): Category::getCategories('xxx') #1 {main} thrown in /in/eMj68 on line 9
Process exited with code 255.

preferences:
93.3 ms | 409 KiB | 5 Q