¿Usando una variable en otra clase?
Frecuentes
Visto 33 veces
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
¿Cómo puedo hacer esto?
1 Respuestas
1
In the construct method, you should do $this->Result = $Result;
en lugar de return $Result;
,
a continuación, utilizar return $this->Result;
in returnLucky()
.
And you should avoid use variable like $result
y $Result
, que es confuso.
respondido 27 nov., 13:02
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php oop or haz tu propia pregunta.
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
@user3026745 The method with same name of the class
Bet
is the construt method. If you are using php 5, use__construct
es mejor. - xdazzI 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
@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. - ramon