我在使用参数时遇到麻烦。我想通过使用参数从其他函数内部的函数中使用变量。但是我不知道如何使用参数。
我的代码是这样的:
class MyClass{
private $nNumber;
public function __construct() {
$this->nNumber = $_POST['txt1'];
}
private function checkNumber() {
$nNumber = $this->nNumber;
if ($nNumber < 0) {
echo "not valid number";
}else{
return $nNumber;
}
}
private function calculateNumber() {
//here I want to use $nNumber too, but I don't know how to pass it by
//
echo 5 * $nNumber;
}
public function returnAnswer() {
$this->calculateNumber();
}
}