Content · Programming · PHP

PHP finfo_close() Function: Usage and Examples

Learn how PHP finfo_close works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Closes a fileinfo resource in older code; it is deprecated in PHP 8.5.

What Is finfo_close() in PHP?

Closes a fileinfo resource in older code; it is deprecated in PHP 8.5.

Its syntax is:

finfo_close(finfo $finfo): bool

Parameters:

  • $finfo — Accepted as finfo; required argument.

Return type: bool. Modern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.

Availability: Requires fileinfo; legacy procedural function.

Example 1: Basic Usage

<?php

echo class_exists("finfo") ? "Fileinfo available" : "Missing";

Output:

Fileinfo available

Modern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.

Example 2: A Different Input

<?php

$detector = new finfo(FILEINFO_MIME_TYPE); echo get_debug_type($detector);

Output:

finfo

Modern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.

Practical Example: Applying It in a Program

<?php

$detector = new finfo(FILEINFO_MIME_TYPE); echo finfo_buffer($detector, "Hello"); unset($detector);

Output:

text/plain

Modern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.

Important Behavior and Edge Cases

  • Key behavior: Modern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.
  • Environment: Requires fileinfo; legacy procedural function.

Comparison With Related Functions

FunctionPurpose
finfo_close()Closes a fileinfo resource in older code; it is deprecated in PHP 8.5.
finfo_open()finfo_open() creates a detector; finfo_close() closes its handle.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Modern PHP uses finfo objects whose lifetime is managed automaticallyModern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.

Key Takeaways

  • Closes a fileinfo resource in older code; it is deprecated in PHP 8.5.
  • Modern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.
  • Requires fileinfo; legacy procedural function.

Summary: Modern PHP uses finfo objects whose lifetime is managed automatically. Avoid relying on finfo_close() in new code.

Share this resourceSend this page to someone who may find it useful.