3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Shape { public function __construct() {} abstract public function area(); abstract public function sides(); public function info() { return "This ".get_class($this)." has ".$this->sides()." sides and an area of ".$this->area()."\n"; } } class Square extends Shape { public function __construct($s) { parent::__construct(); $this->width = $s; } public function area() { return $this->width * $this-width; } public function sides() { return 4; } } class Rectangle extends Square { public function __construct($w,$h) { parent::__construct($w); $this->height = $h; } public function area() { return $this->width * $this->height; } } class Circle extends Shape { public function __construct($r) { parent::__construct(); $this->radius = $r; } public function area() { return $this->radius * $this->radius * M_PI; } public function sides() { return 1; } } $s = new Rectangle(3,15); print($s->info()); $c = new Circle(3); print($c->info()); $q = new Square(3); print($q->info()); ?>
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Creation of dynamic property Rectangle::$width is deprecated in /in/D51ZQ on line 21 Deprecated: Creation of dynamic property Rectangle::$height is deprecated in /in/D51ZQ on line 40 This Rectangle has 4 sides and an area of 45 Deprecated: Creation of dynamic property Circle::$radius is deprecated in /in/D51ZQ on line 54 This Circle has 1 sides and an area of 28.274333882308 Deprecated: Creation of dynamic property Square::$width is deprecated in /in/D51ZQ on line 21 Fatal error: Uncaught TypeError: Unsupported operand types: int * Square in /in/D51ZQ:26 Stack trace: #0 /in/D51ZQ(12): Square->area() #1 /in/D51ZQ(73): Shape->info() #2 {main} thrown in /in/D51ZQ on line 26
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27
This Rectangle has 4 sides and an area of 45 This Circle has 1 sides and an area of 28.274333882308 Fatal error: Uncaught TypeError: Unsupported operand types: int * Square in /in/D51ZQ:26 Stack trace: #0 /in/D51ZQ(12): Square->area() #1 /in/D51ZQ(73): Shape->info() #2 {main} thrown in /in/D51ZQ on line 26
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
This Rectangle has 4 sides and an area of 45 This Circle has 1 sides and an area of 28.274333882308 Notice: Object of class Square could not be converted to number in /in/D51ZQ on line 26 Warning: Use of undefined constant width - assumed 'width' (this will throw an Error in a future version of PHP) in /in/D51ZQ on line 26 Warning: A non-numeric value encountered in /in/D51ZQ on line 26 This Square has 4 sides and an area of 3
Output for 7.3.32 - 7.3.33
This Rectangle has 4 sides and an area of 45 This Circle has 1 sides and an area of 28.274333882308 Warning: Use of undefined constant width - assumed 'width' (this will throw an Error in a future version of PHP) in /in/D51ZQ on line 26 Warning: A non-numeric value encountered in /in/D51ZQ on line 26 This Square has 4 sides and an area of 3
Output for 7.2.0 - 7.2.33
This Rectangle has 4 sides and an area of 45 This Circle has 1 sides and an area of 28.274333882308 Notice: Object of class Square could not be converted to int in /in/D51ZQ on line 26 Warning: Use of undefined constant width - assumed 'width' (this will throw an Error in a future version of PHP) in /in/D51ZQ on line 26 Warning: A non-numeric value encountered in /in/D51ZQ on line 26 This Square has 4 sides and an area of 3
Output for 7.1.0 - 7.1.33
This Rectangle has 4 sides and an area of 45 This Circle has 1 sides and an area of 28.274333882308 Notice: Object of class Square could not be converted to int in /in/D51ZQ on line 26 Notice: Use of undefined constant width - assumed 'width' in /in/D51ZQ on line 26 Warning: A non-numeric value encountered in /in/D51ZQ on line 26 This Square has 4 sides and an area of 3
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
This Rectangle has 4 sides and an area of 45 This Circle has 1 sides and an area of 28.274333882308 Notice: Object of class Square could not be converted to int in /in/D51ZQ on line 26 Notice: Use of undefined constant width - assumed 'width' in /in/D51ZQ on line 26 This Square has 4 sides and an area of 3

preferences:
218.47 ms | 402 KiB | 323 Q