Skip to content

Instantly share code, notes, and snippets.

@kusa-mochi
Created August 6, 2019 13:52
Show Gist options
  • Save kusa-mochi/c67b4a1c3d0679310f6ee431374645a3 to your computer and use it in GitHub Desktop.
Save kusa-mochi/c67b4a1c3d0679310f6ee431374645a3 to your computer and use it in GitHub Desktop.
<?php
// Soda.php
// 名前空間の定義
namespace Mochi\MyNamespace;
// 外部ファイルのインポート
require_once 'Drink.php';
// クラスの継承
class Soda extends Drink
{
// メンバ変数
private $gasLevel = 100;
// コンストラクタ
public function __construct($g = 100)
{
parent::__construct();
$this->SetGasLevel($g);
}
// メソッド
public function EchoParams()
{
parent::EchoParams();
echo ', ガスレベル:'.$this->GetGasLevel().'%';
}
// メソッド
public function GetGasLevel()
{
return $this->gasLevel;
}
// メソッド
public function SetGasLevel($g)
{
if(0<= $g && $g <= 100)
{
$this->gasLevel = $g;
}
else
{
// 何もしない。
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment