Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: six plus three?
(Example: nine)

The Note You're Voting On

corpus-deus at softhome dot net
15 years ago
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.

<< Back to user notes page

To Top