1. Home
  2. Php
  3. Class

Simple class example.

#php
class Shape {

    public $type;
    protected $colour = 'transparent'; // Default value set

    
    // Construct method runs automatically when the Class is called
    public function __construct( $type, $colour ){

        $this->type = $type;
        $this->colour = $colour;

    }

    public function makeSquare(){
        
        $this->type = 'Square';

    }
}

$shape = new Shape( 'Circe', 'Red' );
$shape->makeSquare();
copy
Full Php cheatsheet
Atlas VPN Atlas VPN