In PHP 7 a zval can be reference counted or not. There is a flag in the zval structure which determined this.
There are some types which are never refcounted. These types are null, bool, int and double.
There are other types which are always refcounted. These are objects, resources and references.
And then there are types, which are sometimes refcounted. Those are strings and arrays.
For strings the not-refcounted variant is called an "interned string". If you're using an NTS (not thread-safe) PHP 7 build, which you typically are, all string literals in your code will be interned. These interned strings are deduplicated (i.e. there is only one interned string with a certain content) and are guaranteed to exist for the full duration of the request, so there is no need to use reference counting for them. If you use opcache, these strings will live in shared memory, in which case you can't use reference counting for them (as our refcounting mechanism is non-atomic). Interned strings have a dummy refcount of 1, which is what you're seeing here.
For arrays the not-refcounted variant is called an "immutable array". If you use opcache, then constant array literals in your code will be converted into immutable arrays. Once again, these live in shared memory and as such must not use refcounting. Immutable arrays have a dummy refcount of 2, as it allows us to optimize certain separation paths.
0
. Also, these debug methods don’t seem to be particularly well updated for PHP 7 or they would output the info from thetype_info
field in a zval. – Tortoise