Php/クラス継承について
提供: 初心者エンジニアの簡易メモ
private・・・元のクラス内でのみ呼び出し可能
protected・・・継承クラスからでも呼び出し可能(多重継承もOK)
public・・・継承オブジェクトからでも呼び出し可能
以下サンプルスクリプト
<?php
class sinbol
{
private $private = "private ";
protected $protected = "protected ";
public $public = "public ";
function sinbol()
{
print "シンボルクラス";
print $this->public; // ○
print $this->protected; // ○
print $this->private; // ○
print "<br><br>";
}
}
class ins extends sinbol
{
function ins()
{
print "継承クラス";
print $this->public; // ○
print $this->protected; // ○
// print $this->private; // ×
print "<br><br>";
}
}
$sinbol = new sinbol();
print "シンボルオブジェクト";
print $sinbol->public; // ○
// print $sinbol->protected; // ×
// print $sinbol->private; // ×
print "<br><br>";
$ins = new ins();
print "継承オブジェクト";
print $ins->public; // ○
// print $ins->protected; // ×
// print $ins->private; // ×
print "<br><br>";
?>
