user3026745
user3026745

Reputation: 15

Using a variable in another class?

I have this on my class file

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"; }  }

On my other file I'm doing

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

I am able to get the number 4 (testing) but I can't seem to return $result

How can I do this?

Upvotes: 0

Views: 40

Answers (1)

xdazz
xdazz

Reputation: 160963

In the construct method, you should do $this->Result = $Result; instead of return $Result;,

then use return $this->Result; in returnLucky().

And you should avoid use variable like $result and $Result, which is confusing.

Upvotes: 1

Related Questions