0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I got it to work with your advice, what is the "contruct method", the if result < chance statements? I got it working putting it in the if statement.
@user3026745 The method with same name of the class Bet is the construt method. If you are using php 5, use __construct is better.
I tried putting the construct in the bet class and function but I kept getting undefined variable error. Should I be calling it a different way?
@user3026745 you got two result variable 1 ucfirst and 1 lcfirt can you remove the 1 ucfirst coz i see in your class that you are not using it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.