我在想,如果這個語法是正確的:OOP - 類和子類 - 呼叫子方法
在Classes.php:
Class Cart {
public $Product; // an object handler will be set on this property
public function __construct($user) {
// get a product on user's cart (let's say it's only 1 product) - returns $id
$this->Product = new Product($id);
}
}
Class Product {
public function __construct($id) {
// construct goes here
}
public function Product_Method() {
// product method goes here
}
}
論文字
$cart = new Cart($user);
$product_method = $cart->Product->Product_method();
它看起來佯裝我,因爲$ product被設置爲Public,並且引用一個對象處理程序。
什麼是Product_method()我在定義中看不到 – 2013-04-25 17:45:11
是什麼問題? – Cooper 2013-04-25 17:47:10
你爲什麼不嘗試在你的計算器?一個有用的相關問題:http://stackoverflow.com/questions/2307097/method-chains-php-oop – 2013-04-25 17:47:21