3v4l.org

run code in 300+ PHP versions simultaneously
<?php class With_Magic_Methods { private $_prop = array(); protected $compat_fields = array( '_prop' ); public function __get( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name; } } public function __set( $name, $value ) { if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name = $value; } } public function __isset( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return isset( $this->$name ); } return false; } public function __unset( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { unset( $this->$name ); } } } class No_Magic_Methods { public $_prop = array(); } function run_test() { $with_magic_methods = new With_Magic_Methods(); $no_magic_methods = new No_Magic_Methods(); echo "** Test `__get()` **\n"; echo "With magic methods: "; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); echo "\n\n ** Test `__isset()` **\n"; echo "With magic methods: "; var_dump( isset( $with_magic_methods->_prop ) ); echo "No magic methods: "; var_dump( isset( $no_magic_methods->_prop ) ); echo "\n\n ** Test `__set()` **\n"; $new_value = array( 'test' ); $with_magic_methods->_prop = $new_value; $no_magic_methods->_prop = $new_value; echo "With magic methods: "; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); echo "\n\n ** Test `__isset()` after an `__unset()` **\n"; unset( $with_magic_methods->_prop ); unset( $no_magic_methods->_prop ); echo "With magic methods:"; var_dump( isset( $with_magic_methods->_prop ) ); echo "No magic methods: "; var_dump( isset( $no_magic_methods->_prop ) ); echo "\n\n ** Test `__get()` after an __unset() **\n"; echo "With magic methods:"; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); echo "\n\n ** Test `__set()` after an __unset() **\n"; $new_value = array( 'test after an unset' ); $with_magic_methods->_prop = $new_value; $no_magic_methods->_prop = $new_value; echo "With magic methods:"; var_dump( $with_magic_methods->_prop ); echo "No magic methods: "; var_dump( $no_magic_methods->_prop ); } run_test();

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.110.0060.00320.94
8.3.100.0040.00824.06
8.3.90.0000.00826.77
8.3.80.0060.00318.43
8.3.70.0110.01117.00
8.3.60.0150.00318.79
8.3.50.0150.00618.84
8.3.40.0100.00323.68
8.3.30.0110.01120.25
8.3.20.0050.00324.18
8.3.10.0050.00324.66
8.3.00.0040.00426.16
8.2.230.0080.00022.58
8.2.220.0150.00337.54
8.2.210.0040.00426.77
8.2.200.0030.00618.29
8.2.190.0160.00616.63
8.2.180.0070.01418.29
8.2.170.0070.00719.08
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0000.00819.54
8.2.110.0070.00320.43
8.2.100.0060.00322.07
8.2.70.0120.00279.33
8.1.290.0060.00318.88
8.1.280.0110.01425.92
8.1.270.0040.00424.66
8.1.260.0030.00626.35
8.1.250.0040.01128.09
8.1.240.0100.00020.33
8.1.230.0070.00418.63
8.1.200.0090.00479.33

preferences:
27.44 ms | 403 KiB | 5 Q