Last active
August 6, 2019 13:50
-
-
Save kusa-mochi/6ea9f2c1c5774ebc22c451fc415331ae to your computer and use it in GitHub Desktop.
クラス定義の例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Drink.php | |
// 名前空間の定義 | |
namespace Mochi\MyNamespace; | |
// クラスの定義 | |
class Drink | |
{ | |
// メンバ変数 | |
private $amount = 500; | |
// コンストラクタ | |
public function __construct($a = 500) | |
{ | |
$this->SetAmount($a); | |
} | |
// メソッド | |
public function EchoParams() | |
{ | |
echo '残り'.$this->GetAmount().'ml'; | |
} | |
// メソッド | |
public function GetAmount() | |
{ | |
return $this->amount; | |
} | |
// メソッド | |
public function SetAmount($a) | |
{ | |
if(0 <= $a && $a <= 500) | |
{ | |
$this->amount = $a; | |
} | |
else | |
{ | |
// 何もしない。 | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment