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); 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);
based on lR3Wp
Output for 7.0.0 - 7.1.0
<pre>separate variables 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 4.3.0 - 5.6.28
<pre>separate variables 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)