3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function do_something() { echo "class A did something"; } } class B { private $arr = array(); private $current_index = 0; public function add_new_A() { $new_a = new A; $this->arr[$this->current_index] = $new_a; $this->current_index++; } public function get_an_A_by_index($index) { return $this->arr[$index]; } public function do_something_with_A_member_inside_array($index) { self::get_an_A_by_index($index)->do_something(); } } $b = new B; $b->add_new_a(); $b->add_new_a(); echo print_r($b->get_an_A_by_index(0)); echo "\n"; $b->do_something_with_A_member_inside_array(0); // returns error
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
A Object ( ) 1 class A did something
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.

preferences:
193.25 ms | 407 KiB | 5 Q