3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<pre><?php $var1 = 'ccc'; $var2 = 'ccc'; echo "separate variables\n"; debug_zval_dump($var1, $var2); echo "Copying variable just adds references to the same value\n"; $copy = $var1; debug_zval_dump($var1, $copy); echo "Using a reference adds references to the same value \n"; $reference =& $var2; debug_zval_dump($var2, $reference); echo "Using a copy and a reference of the same value actually creates a clone \n"; $reference2 =& $var1; debug_zval_dump($var1, $copy, $reference2);
Output for 7.0.0 - 7.1.0
<pre>separate variables string(3) "ccc" refcount(1) string(3) "ccc" refcount(1) Copying variable just adds references to the same value string(3) "ccc" refcount(1) string(3) "ccc" refcount(1) Using a reference adds references to the same value string(3) "ccc" refcount(1) string(3) "ccc" refcount(1) Using a copy and a reference of the same value actually creates a clone string(3) "ccc" refcount(1) string(3) "ccc" refcount(1) string(3) "ccc" refcount(1)
Output for hhvm-3.10.0 - 3.12.0
<pre>separate variables Warning: debug_zval_dump() expects exactly 1 parameter, 2 given in /in/lR3Wp on line 6 Copying variable just adds references to the same value Warning: debug_zval_dump() expects exactly 1 parameter, 2 given in /in/lR3Wp on line 11 Using a reference adds references to the same value Warning: debug_zval_dump() expects exactly 1 parameter, 2 given in /in/lR3Wp on line 15 Using a copy and a reference of the same value actually creates a clone Warning: debug_zval_dump() expects exactly 1 parameter, 3 given in /in/lR3Wp on line 19
Output for 4.3.0 - 5.6.28
<pre>separate variables string(3) "ccc" refcount(2) string(3) "ccc" refcount(2) Copying variable just adds references to the same value string(3) "ccc" refcount(4) string(3) "ccc" refcount(4) Using a reference adds references to the same value string(3) "ccc" refcount(1) string(3) "ccc" refcount(1) Using a copy and a reference of the same value actually creates a clone string(3) "ccc" refcount(1) string(3) "ccc" refcount(2) string(3) "ccc" refcount(1)