代碼返回未定義的變量,我認爲有些事情是錯的,我寫的功能,它應該劃分$value
和$splitfee
OOP PHP價格計算器
class Product {
public $name;
public $value;
public $price;
public $splitfee;
function split() {
$this->value->splitfee = $this->$value/$splitfee;
}
}
$product_one = new Product();
$product_one->name = "potato";
$product_one->price = 100;
$product_two = new Product();
$product_two->name = "tomato";
$product_two->value = 200;
$product_two->splitfee = 200;
$product_three = new Product();
$product_three->name = "auto";
$product_three->price = 300;
echo $product_one->name . " is " . $product_one->price . " $" . "<br />";
echo $product_two->name . " is " . $product_two->split() . " $" . "<br />";
您的功能正文不正確。這裏的splitfee是什麼? –
這應該是按產品價值劃分的費用,例如200/30,但是我看到我將splitfee設置爲200 –
@NadanMarenkovićhttp://phpio.net/s/1gkv –