本文整理匯總了PHP中C::operation方法的典型用法代碼示例。如果您正苦於以下問題:PHP C::operation方法的具體用法?PHP C::operation怎麽用?PHP C::operation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類C
的用法示例。
在下文中一共展示了C::operation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: B
echo "類的繼承<br/>";
$b = new B();
//$b -> operation2(); Fatal error: Call to protected method A::operation2() from context ''
$b->say_something();
$b->lila = 10;
$b->do_something();
$b->lilb = 10;
class C
{
public $attribute = "default value";
function operation()
{
echo "Something<br/>";
echo "The value of \$attribute is " . $this->attribute . "<br/>";
}
}
class D
{
public $attribute = "different value";
function operation()
{
echo "Something else<br/>";
echo "The value of \$attribute is " . $this->attribute . "<br/>";
}
}
echo "方法與屬性的重載<br/>";
$c = new C();
$c->operation();
$d = new D();
$d->operation();
//parent::operation();
示例2: A
public $test2 = 'Java';
public $test3 = 'C++';
}
$a = new A();
foreach ($a as $output) {
echo $output . '<br />';
}
//類的繼承關係
class B
{
public $test = "very large";
function operation()
{
echo "welcome.<br /><br />";
echo "The value of \$test is {$this->test}. <br /><br />";
}
}
class C extends B
{
public $test = "perfect";
function operation()
{
echo "welcome back <br /><br />";
echo "The value of \$test is {$this->test} <br /><br />";
}
}
$a = new B();
$a->operation();
$b = new C();
$b->operation();