Every day

Here are two PHP functions (although one’s actually from an extension) that I didn’t know existed, but give you some good insight into your variables, especially when you’re mucking around with more complicated stuff: debug_zval_dump and xdebug_debug_zval.

Both give you more information about the underlying representation of your variables: in particular, what the refcount is for that particular value. Note, however, that while it’s literally called the “reference count”, a refcount greater than one doesn’t imply that the variable is actually a reference due to PHP’s “copy on write” semantics. XDebug’s version of the method wins here, because it also dumps is_ref, which does flag a reference.

(See Sara Golemon’s You’re being lied to or Derick Rethan’s References in PHP [PDF] for more.)

Leave a Reply