Skip to content

Instantly share code, notes, and snippets.

@kusa-mochi
Last active August 6, 2019 13:50
Show Gist options
  • Save kusa-mochi/6ea9f2c1c5774ebc22c451fc415331ae to your computer and use it in GitHub Desktop.
Save kusa-mochi/6ea9f2c1c5774ebc22c451fc415331ae to your computer and use it in GitHub Desktop.
クラス定義の例
<?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