Advertisement
atanasovetr

class Square

Mar 17th, 2021
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2. class Square {
  3.     public $width;
  4.     public $height;
  5.  
  6.     function __construct($width, $height) {
  7.         $this->width = $width;
  8.         $this->height = $height;
  9.     }
  10.  
  11.     function area(){
  12.         $area = $this->width * $this->height;
  13.         return $area;
  14.     }
  15.  
  16.     function get_width() {
  17.         return $this->width;
  18.     }
  19.     function get_height() {
  20.         return $this->height;
  21.     }
  22.  
  23.     function setWidth($width){
  24.         $this->width = $width;
  25.     }
  26.  
  27.     function setHeight($height){
  28.         $this->height = $height;
  29.     }
  30. }
  31.  
  32. $square1 = new Square(7, 8);
  33. echo $square1->area();
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement