3v4l.org

run code in 300+ PHP versions simultaneously
<?php function vars_are_referenced (&$var1, &$var2) { // What we are doing *will* throw an error (I said it was nasty ;-) ) $oldER = error_reporting(); $oldDE = ini_get('display_errors'); error_reporting(0); ini_set('display_errors', 0); // We need to use output buffering, we don't want to break any existing // buffering so we cache the contents of the buffer $oldBuffer = ob_get_length() ? ob_get_clean() : NULL; // If the values are not identical, definitely not a match if ($var1 !== $var2) return FALSE; // Now we inspect the zval of $var1 ob_start(); debug_zval_dump(&$var1); preg_match('/\brefcount\((\d+)\)(?:\b|$)/', ob_get_clean(), $matches); $var1RefCountBefore = (int) $matches[1]; // If they are the same, this will increase the refcount $temp = &$var2; // Inspect the zval of $var1 again ob_start(); debug_zval_dump(&$var1); preg_match('/\brefcount\((\d+)\)(?:\b|$)/', ob_get_clean(), $matches); $var1RefCountAfter = (int) $matches[1]; // If refcount is now greater, they are the same $result = $var1RefCountAfter > $var1RefCountBefore; // Repopulate the output buffer if necessary if ($oldBuffer !== NULL) { ob_start(); echo $oldBuffer; } // Turn error reporting back to correct level error_reporting($oldER); ini_set('display_errors', $oldDE); return $result; } function test_ref_fail () { $a = 1; $var_name = 'a'; var_dump(vars_are_referenced($GLOBALS['a'], $a)); } function test_ref_success_1 () { global $a; $var_name = 'a'; var_dump(vars_are_referenced($GLOBALS['a'], $a)); } function test_ref_success_2 (&$a) { $var_name = 'a'; var_dump(vars_are_referenced($GLOBALS['a'], $a)); } $a = 1; $b = &$a; var_dump(vars_are_referenced($a, $b)); test_ref_fail(); test_ref_success_1(); test_ref_success_2($a); ?>

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)
5.4.140.0130.04312.07
5.4.130.0110.04412.06
5.4.120.0120.04112.02
5.4.110.0090.04612.01
5.4.100.0130.04112.02
5.4.90.0100.04412.01
5.4.80.0180.05812.02
5.4.70.0120.03712.01
5.4.60.0100.04012.01
5.4.50.0080.04112.01
5.4.40.0110.04012.00
5.4.30.0080.04412.00
5.4.20.0110.04312.00
5.4.10.0120.04211.99
5.4.00.0100.04411.49
5.3.290.0050.03912.80
5.3.280.0120.04312.71
5.3.270.0120.04712.73
5.3.260.0110.04812.72
5.3.250.0120.04812.72
5.3.240.0130.05212.72
5.3.230.0120.04212.71
5.3.220.0100.04112.68
5.3.210.0110.04212.68
5.3.200.0110.04112.68
5.3.190.0100.04312.68
5.3.180.0120.05812.67
5.3.170.0130.04712.67
5.3.160.0150.06012.67
5.3.150.0130.05012.67
5.3.140.0130.04712.67
5.3.130.0130.04912.66
5.3.120.0110.05012.66
5.3.110.0110.04912.66
5.3.100.0110.04812.14
5.3.90.0160.05712.13
5.3.80.0110.04912.12
5.3.70.0100.04812.12
5.3.60.0110.04712.10
5.3.50.0080.04912.05
5.3.40.0130.05412.05
5.3.30.0090.04712.01
5.3.20.0100.04511.79
5.3.10.0120.03711.76
5.3.00.0100.04411.74

preferences:
137.04 ms | 1394 KiB | 7 Q