我相信這對大多數人來說看起來像是一個愚蠢的問題。然而,我一直在抨擊我的頭一陣子。 來自ASP.NET/C#,我試圖現在使用PHP。但整個OOrintation給我很難。面向對象的調用方法php
我有以下代碼:
<html>
<head>
</head>
<body>
<?php
echo "hello<br/>";
class clsA
{
function a_func()
{
echo "a_func() executed <br/>";
}
}
abstract class clsB
{
protected $A;
function clsB()
{
$A = new clsA();
echo "clsB constructor ended<br/>";
}
}
class clsC extends clsB
{
function try_this()
{
echo "entered try_this() function <br/>";
$this->A->a_func();
}
}
$c = new clsC();
$c->try_this();
echo "end successfuly<br/>";
?>
</body>
</html>
要我簡單的理解這個代碼會導致下列行:
你好
clsB構造結束
進入try_this ()函數
a_func()執行
但是,它不運行 'a_func',我得到的是:
你好
clsB構造結束
進入try_this()函數
任何人都可以發現問題嗎?
謝謝先進。
在這種情況下,他'could',但沒有人知道,如果這是他想要做什麼,因爲也許A類無關,與分級結構:) – tim 2012-02-02 14:00:08
@Alexandrew真正的B和C,但只是給它一個答案:-) – 2012-02-02 14:29:32
是的,那就是我的意思。我知道它必須處理這樣愚蠢的事情。有效。太感謝了。 – dsb 2012-02-02 14:45:12