Skip to content

Instantly share code, notes, and snippets.

@kana
Created August 17, 2017 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kana/ebf4d8daa52d6289e77c25ad2342ffd5 to your computer and use it in GitHub Desktop.
Save kana/ebf4d8daa52d6289e77c25ad2342ffd5 to your computer and use it in GitHub Desktop.
<?php
$a = 1;
debug_zval_dump($a);
//==> long(1) refcount(2)
// Novice: Huh? Why is refcount 2? The value is only pointed by $a, so refcount must be 1!
// Tatsujin: PHP uses copy-on-write. The value is passed by value to debug_zval_dump.
// It doesn't modify the passed value. The value is shared by $a and debug_zval_dump.
// Therefore refcount is 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment