what object?

class

class: general view

<?php

class Mac {
}


new operator : making mac from general view

<?php

class Mac {
    public $ver; // $ver is NULL default so you can initialize `public $ver = ''`
}

$a = new Mac(); // instance
$a->ver = 'mac book air';
$b = new Mac(); // instance
$b->ver = 'mac book pro';


  • allow operator (->) : refer to property of instance
  • public : can access anywhere
  • private : can not access from external
<?php

class Mac {
    private $ver = ''; // property
    public show_ver ($ver) { // method
        $this->ver = "'current is' . $ver . 'version.'";
    public get_ver() {
        return $this->ver;
    }


construct

When you make instance construct method is called.

<?php

class Mac {

    private $ver = '';

    public function __construct($ver) {
        $this->show_ver($ver);
    }

    public function show_ver($ver) {
        $this->ver = "'current ver is' . $ver . ";
    }

    public function get_ver() {
        return $this->ver;
    }
}


What self?

new self create instance itself in class instead of new class.