|
クラスの作成 |
|
class User {
public $name;
public $email;
public function __construct($name, $email) {
$this->name = $name;
$this->email = $email;
}
public function sayHi() {
echo "hi! my name is ".$this->name;
}
}
|
|
|
インスタンスの生成 |
|
$tom = new User("tom", "dummy@dummy.com");
$bob = new User("bob", "dummy@dummybob.com");
|
|
|
メソッドの実行 |
|
echo $tom->name;
echo $tom->sayHi();
echo $bob->sayHi();
|
|
|
|
|
|