3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php namespace SimonEq; interface ImageInterface { function getFileName(); } class Image implements ImageInterface { private $fileName; public function __construct($fileName) { $this->fileName = $fileName; } public function getFileName() { return $this->fileName; } } interface TransformationInterface { function transform(ImageInterface $image); } class TransformationAggregate implements TransformationInterface { private $transformationArray = []; public function __construct($transformationArray) { $this->transformationArray = $transformationArray; } public function transform(ImageInterface $image) { foreach ($this->transformationArray as $transformation) { $transformation->transform($image); } } } class CropTransformation implements TransformationInterface { private $width; private $height; public function __construct($width, $height) { $this->width = (int) $width; $this->height = (int) $height; } public function transform(ImageInterface $image) { printf('Image "%s" transformed with %s' . PHP_EOL, $image->getFileName(), print_r($this, true)); } } class ResizeTransformation implements TransformationInterface { private $width; private $height; private $resample; public function __construct($width, $height, $resample) { $this->width = (int) $width; $this->height = (int) $height; $this->resample = (bool) $resample; } public function transform(ImageInterface $image) { printf('Image "%s" transformed with %s' . PHP_EOL, $image->getFileName(), print_r($this, true)); } } class WatermarkTransformation implements TransformationInterface { private $image; public function __construct(ImageInterface $image) { $this->image = $image; } public function transform(ImageInterface $image) { printf('Image "%s" transformed with %s' . PHP_EOL, $image->getFileName(), print_r($this, true)); } } $image = new Image('FluffyCat.jpg'); $transformation = new TransformationAggregate([ new CropTransformation(200, 400), new WatermarkTransformation(new Image('MyWaterMark.png')), new ResizeTransformation(100, 200, true), ]); $transformation->transform($image);
Output for 5.4.0 - 7.1.0
Image "FluffyCat.jpg" transformed with SimonEq\CropTransformation Object ( [width:SimonEq\CropTransformation:private] => 200 [height:SimonEq\CropTransformation:private] => 400 ) Image "FluffyCat.jpg" transformed with SimonEq\WatermarkTransformation Object ( [image:SimonEq\WatermarkTransformation:private] => SimonEq\Image Object ( [fileName:SimonEq\Image:private] => MyWaterMark.png ) ) Image "FluffyCat.jpg" transformed with SimonEq\ResizeTransformation Object ( [width:SimonEq\ResizeTransformation:private] => 100 [height:SimonEq\ResizeTransformation:private] => 200 [resample:SimonEq\ResizeTransformation:private] => 1 )
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/rjN2W on line 39
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/rjN2W on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/rjN2W on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/rjN2W on line 3
Process exited with code 255.