note 124563 added to function.imagedestroy

From: Date: Fri, 03 Jan 2020 13:16:07 +0000
Subject: note 124563 added to function.imagedestroy
Groups: php.notes 
Request: Send a blank email to php-notes+get-213727@lists.php.net to get a copy of this message
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. ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 201.234.88.122) ---- Manual Page -- http://php.net/manual/en/function.imagedestroy.php Edit -- https://master.php.net/note/edit/124563 Del: integrated -- https://master.php.net/note/delete/124563/integrated Del: useless -- https://master.php.net/note/delete/124563/useless Del: bad code -- https://master.php.net/note/delete/124563/bad+code Del: spam -- https://master.php.net/note/delete/124563/spam Del: non-english -- https://master.php.net/note/delete/124563/non-english Del: in docs -- https://master.php.net/note/delete/124563/in+docs Del: other reasons-- https://master.php.net/note/delete/124563 Reject -- https://master.php.net/note/reject/124563 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#213727) next »