Resources
Resources are the weird kid in the corner of the PHP types party. Maybe you can relate?
If you call gettype
on a resource, you will get null
. This is because they are a bit special. They are like wormholes into the dimension beyond the realms of PHP. All we know is they exist, but what goes on beyond their event horizon we can only speculate…
Resources that you are likely to have already come across on a regular basis are file pointers when using fopen
and database connections. There are in fact numerous resources that you can open in PHP and you can read all about them in the manual:
PHP: List of Resource Types - Manual
https://www.php.net/manual/en/resource.php
The good news is that in PHP 8, the resource types are gradually being hunted down and replaced with more useful types – namely objects. Already, the curl_init
function now returns a CurlHandle
class. You still can't really get anything useful from it, but you can at least do bas...