I’m wondering if it’s possible for a valid PHP Resource to have an ID of 0. I am getting database connection resources and so far they have all been non-zero positive integers. Just curious what the range of potential IDs is for resources.
Share
The resource id may be in the range of an
int. Search for “resource” or “ZEND_FETCH_RESOURCE” in the source code directory of PHP via the terminal. Then you’ll see the function:(file
./Zend/zend_list.c, line 110)Inside the function, you’ll see that
passed_idis the resource’s id and it’s of typeint.Normally, libraries pass a default id of
-1, for example in file./ext/mysql/php_mysql.c, line 1060.In general you can assume that all the libraries will pass a real/exists resource id with value greater than 0, but that’s not a rule that every library must follow – it is possible to pass a negative resource id or 0.