ここでは 簡単なメモ帳のようなプログラム SimpleNotepad
クラスを作成します。SimpleNotepad
クラスの仕様は以下のとおりです。
プロパティ | 意味 |
---|---|
$input_string |
入力された文字列 |
メソッド | 処理内容 |
---|---|
type |
$string 引数で受け取った文字列データを $input_string プロパティに追加する |
show |
$input_string プロパティの内容を出力する |
コンストラクタ | 処理内容 |
---|---|
__construct |
$input_string プロパティを "" 空文字で初期化する |
問題 1
次のプログラム( notepad_runner1.php
)があります。
notepad_runner1.php
<?php
require_once("SimpleNotepad.php");
$notepad = new SimpleNotepad();
$notepad->type("one");
$notepad->show(); # => "one"
次の実行結果のとおり動作するプログラム( SimpleNotepad.php
)を作成してください。
実行結果
$ php notepad_runner1.php
one
SimpleNotepad.php
<?php
class SimpleNotepad
{
protected $input_string;
public function __construct()
{
$this->input_string = "";
}
public function type($string)
{
# TODO
}
public function show()
{
echo $this->input_string . PHP_EOL;
}
}
type
メソッドを実装してください。