我想知道这种语法是否正确:
在 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 并引用对象处理程序。