PHP 7 Solutions by David Powers

PHP 7 Solutions by David Powers

Author:David Powers
Language: eng
Format: epub
ISBN: 9781484243381
Publisher: Apress


8.Try a number of tests, omitting the trailing slash from the value passed to setDestination() or selecting a nonexistent folder. Also pass invalid values for the maximum size and suffix. An invalid destination folder throws an exception, but the others fail silently, using the default value for the maximum size or _thb for the suffix.

If necessary, compare your code with Thumbnail_02.php in ch10/PhpSolutions/Image and create_thumb_03.php in the ch10 folder.

You might not agree with my decision to fail silently when the values passed as arguments are invalid. By now, though, you should have sufficient experience of conditional statements to adapt the code to your own requirements. For example, if you want the setMaxSize() method to throw an exception instead of failing silently, check that the value is greater than zero and add an else block to handle the error. This is how you would adapt the setMaxSize() method: protected function setMaxSize($size) {

if (is_numeric($size) && $size > 0) {

$this->maxSize = $size;

} else {

throw new \Exception('The value for setMaxSize() must be a positive number.');

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.