Skip to content

Commit f42a502

Browse files
author
Mitch
committed
Throw error if the object is instantiated without a file, when not called from one of the static methods
This is so save() resize cannot be called on an object that doesn't have an image set up
1 parent 4452e3a commit f42a502

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/ImageResize.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ public static function createFromString($imageData) {
7272
*/
7373
public function __construct($filename = null)
7474
{
75-
if (!empty($filename)) {
75+
if ($filename !== null) {
7676
$this->loadFromFile($filename);
77+
} else {
78+
// if no filename is provided, we want to throw an exception if
79+
// the object was not created in one of it's static method
80+
$backtrace = debug_backtrace();
81+
82+
if (!isset($backtrace[1]['class']) || $backtrace[1]['class'] != __CLASS__) {
83+
throw new \Exception('No image provided');
84+
}
7785
}
7886
}
7987

0 commit comments

Comments
 (0)