3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Image { public function __construct($path) { $this->image = imagecreatefromjpeg($path); } public function getSize() { return array(imagesx($this->image), imagesy($this->image)); } } class ImageProxy extends Image { protected $image; public function __construct($path) { $this->path = $path; } private function init() { if ( ! $this->image) { $this->image = new Image($this->path); } } public function getSize() { $this->init(); return $this->image->getSize(); } } $img1 = new ImageProxy('/path/to/image1.jpg'); var_dump(memory_get_usage()); // ~200Kb $img2 = new ImageProxy('/path/to/image2.jpg'); var_dump(memory_get_usage()); // ~200Kb $img3 = new ImageProxy('/path/to/image3.jpg'); var_dump(memory_get_usage()); // ~200Kb $size1 = $img1->getSize(); var_dump(memory_get_usage()); // ~4Mb $size2 = $img2->getSize(); var_dump(memory_get_usage()); // ~8Mb
Output for 7.4.0 - 7.4.1
int(393024) int(393488) int(393920) Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt:5 Stack trace: #0 /in/B0EXt(21): Image->__construct('/path/to/image1...') #1 /in/B0EXt(26): ImageProxy->init() #2 /in/B0EXt(38): ImageProxy->getSize() #3 {main} thrown in /in/B0EXt on line 5
Process exited with code 255.
Output for 7.3.0 - 7.3.13
int(393016) int(393480) int(393912) Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt:5 Stack trace: #0 /in/B0EXt(21): Image->__construct('/path/to/image1...') #1 /in/B0EXt(26): ImageProxy->init() #2 /in/B0EXt(38): ImageProxy->getSize() #3 {main} thrown in /in/B0EXt on line 5
Process exited with code 255.
Output for 7.2.0 - 7.2.26
int(388896) int(389360) int(389792) Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt:5 Stack trace: #0 /in/B0EXt(21): Image->__construct('/path/to/image1...') #1 /in/B0EXt(26): ImageProxy->init() #2 /in/B0EXt(38): ImageProxy->getSize() #3 {main} thrown in /in/B0EXt on line 5
Process exited with code 255.
Output for 7.1.0 - 7.1.33
int(352160) int(352624) int(353056) Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt:5 Stack trace: #0 /in/B0EXt(21): Image->__construct('/path/to/image1...') #1 /in/B0EXt(26): ImageProxy->init() #2 /in/B0EXt(38): ImageProxy->getSize() #3 {main} thrown in /in/B0EXt on line 5
Process exited with code 255.
Output for 7.0.0 - 7.0.33
int(352144) int(352608) int(353040) Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt:5 Stack trace: #0 /in/B0EXt(21): Image->__construct('/path/to/image1...') #1 /in/B0EXt(26): ImageProxy->init() #2 /in/B0EXt(38): ImageProxy->getSize() #3 {main} thrown in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.6.0 - 5.6.40
int(228400) int(229064) int(229680) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.38
int(228384) int(229032) int(229656) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.4.10 - 5.4.45
int(228856) int(229496) int(230104) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.4.0 - 5.4.9
int(228856) int(229520) int(230136) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.3.11 - 5.3.29
int(635056) int(635720) int(636360) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.3.0 - 5.3.10
int(634752) int(635416) int(636056) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.2.10 - 5.2.17
int(93848) int(94496) int(95112) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.2.7 - 5.2.9
int(94840) int(95456) int(96072) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.2.3 - 5.2.6
int(95160) int(95776) int(96392) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.2.2
int(93056) int(93672) int(94288) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.2.1
int(93104) int(93720) int(94336) Fatal error: Call to undefined function imagecreatefromjpeg() in /in/B0EXt on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.1 - 5.1.6, 5.2.0
Fatal error: Call to undefined function memory_get_usage() in /in/B0EXt on line 32
Process exited with code 255.
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/B0EXt on line 41
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/B0EXt on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/B0EXt on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/B0EXt on line 4
Process exited with code 255.

preferences:
217.36 ms | 401 KiB | 325 Q