在另一个类中使用变量


Using a variable in another class?

我的类文件中有这个

class Bet {    
  private $Client;
  private $Secret;
  private $Server;  
  private $result;  
  private $Result;
  public function Bet($Type, $Chance) {    
      $this->Client = md5(uniqid(rand(), true));
      $this->Secret = md5(uniqid(rand(), true));
      $this->Server = md5(uniqid(rand(), true));
      if($Type == 'auto') {    
              $hash  = hash('sha512', $this->Client . $this->Secret . $this->Server);
              $Result = round(hexdec(substr($hash, 0, 8)) / 42949672.95, 2);
                  if($Result < $Chance) {
                      $this->result = true;
                      return $Result;
                  } else {
                      $this->result = false; 
                     return $Result;                     
                  }      
      }
  }
  /**
  * @return boolean
  */
  public function isReturnLessThanChance() { return $this->result; }
  public function returnLucky() { return "4"; }  }

在我的另一个文件上,我正在进行

$bet = new Bet('auto', $chance);
$lucky = $bet->returnLucky();

我可以得到数字4(测试),但我似乎无法返回$result

我该怎么做?

在构造方法中,应该执行$this->Result = $Result;而不是return $Result;

则在CCD_ 4中使用CCD_。

您应该避免使用像$result$Result这样的变量,这会让人感到困惑。