note 96191 added to function.imagedestroy

From: Date: Sat, 13 Feb 2010 02:33:47 +0000
Subject: note 96191 added to function.imagedestroy
Groups: php.notes 
Request: Send a blank email to php-notes+get-165931@lists.php.net to get a copy of this message
In theory creating an image object and calling imagedestroy in your destructor should be a good way of doing it; something like: final class My_Image() { private $img; public function __construct() { $this->img = imagecreatetruecolor(); ... other stuff ... } public function __destruct() { if(is_resource($this->img)) { imagedestroy($this->img); } } ... other methods... } I check that $this->img is a resource in case imagecreatetruecolor() fails or you null the value somewhere down the line from a method call meaning that $this->img is NOT a resource, in which case imagedestroy is an unecessary function call that just fails with a warning message. ---- Server IP: 78.110.173.36 Probable Submitter: 94.171.69.195 ---- Manual Page -- http://www.php.net/manual/en/function.imagedestroy.php Edit -- https://master.php.net/note/edit/96191 Del: integrated -- https://master.php.net/note/delete/96191/integrated Del: useless -- https://master.php.net/note/delete/96191/useless Del: bad code -- https://master.php.net/note/delete/96191/bad+code Del: spam -- https://master.php.net/note/delete/96191/spam Del: non-english -- https://master.php.net/note/delete/96191/non-english Del: in docs -- https://master.php.net/note/delete/96191/in+docs Del: other reasons-- https://master.php.net/note/delete/96191 Reject -- https://master.php.net/note/reject/96191 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165931) next »