Speed up development with full-stack environments for every branch.

Learn More

How to implement the DomainException class [PHP and spl]

11 Runs 115 Views 5 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php
ini_set('display_errors',1);
/*
 * PHP SPL - How to implement the DomainException class
 */

//create a basic image resource
$imageResource = imagecreatetruecolor(120, 20);
//set an invalid image type to trigger an exception
$imageType = 'asd';

switch ($imageType) {
    case 'jpg':
    case 'jpeg':
        header('Content-type: image/jpeg');
        imagejpeg($imageResource);
        break;
    case 'png':
        header('Content-type: image/png');
        imagepng($imageResource);
        break;
    default:
        //throws a new DomainException
        throw new DomainException('Unknown image type: ' . $imageType);
        break;
}
imagedestroy($imageResource);
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).