Voting

: min(five, six)?
(Example: nine)

The Note You're Voting On

devel at kijote dot com dot ar
5 years ago
Important note: When the imagedestroy is called, the resource is freed but the printed resource output is the same as before calling the function:

<?php

$img
= imagecreate(1, 1);

print_r([$img, $img ? 'TRUE': 'FALSE', is_resource($img) ? 'TRUE' : 'FALSE', get_resource_type($img) ?: 'FALSE']);

/*
Result:
Array
(
[0] => Resource id #1
[1] => TRUE
[2] => TRUE
[3] => gd

)
*/

imagedestroy($img);

print_r([$img, $img ? 'TRUE': 'FALSE', is_resource($img) ? 'TRUE' : 'FALSE', get_resource_type($img) ?: 'FALSE']);

/*
Result:
Array
(
[0] => Resource id #1
[1] => TRUE
[2] => FALSE
[3] => Unknown
)
*/
?>

As you can see in the above example, the first index in array is TRUE in both cases. So, despite the common thinking you can't trust in something like:

<?php

if ($img) { // it's casted as boolean and returns true even after imagedestroy is called
// do something
}

?>

If you need to ensure the availability of a certain resource, you must to use is_resource and get_resource_type functions.

<< Back to user notes page

To Top