The PHP Function finfo_close
Functions are a powerful way to separate and re-use code in PHP. They are also an important part of modularization, allowing you to break large applications into smaller pieces that can be easily understood and executed by other developers. In this article, we’ll explore the php function finfo_close, along with some of the other new and improved functions that PHP has to offer.
finfo_close closes the instance opened by finfo_open(). This function is used to perform checks on binary data in a string, like a file or input. It is a new feature that was added in PHP 8.1 to improve the security of the language. For example, the function can help prevent malicious uploads of executable files by checking whether the file actually contains an image or not.
PHP 8.1 now displays a warning if an argument in a compact() function contains non-string or array of strings values. This is a part of the resource to object migration in the finfo extension, where procedural APIs have been replaced by class objects.
Another new feature in PHP 8.1 is the ability to use pure intersection types. When a function declares this type, it will only accept values that fulfill all of its declared types. For example, if the function takes an integer and a string, it will raise a fatal error if the value is not int or string.
Another improvement to PHP is the addition of a float-to-integer deprecation notice. This will stop floats from being implicitly coerced to integers, which may result in unintended fractional loss. This change is similar to the kind declarations introduced in PHP 7.