【发布时间】:2013-04-25 17:44:05
【问题描述】:
我想知道这个语法是否正确:
在 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() 我在定义中没有看到
-
有什么问题?
-
这不是我所说的子类,更多的是在属性上调用方法,但只要
$cart->Product不是unset()就可以了。 -
你试过了吗? @LucasTourinhoCavalcante
-
是的。没有为我工作。但我希望这是一些代码错误,而不是不正确的语法。