<?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());
?>

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.10

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.3.20 - 7.0.20

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