note 96191 modified in function.imagedestroy by danbrown

From: Date: Sat, 13 Feb 2010 02:34:42 +0000
Subject: note 96191 modified in function.imagedestroy by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165932@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: <?php 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. --was-- 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. http://php.net/manual/en/function.imagedestroy.php

« previous php.notes (#165932) next »