icaro_ 0 Denunciar post Postado Março 8, 2012 Olá Galera Bom dia..! Estou a estudar PHP , Logo estou a desenvolver um projetinho afetuar calculos Ohmicos(resistencia eletrica etc...) Vamos a Duvida... Criei uma class para efetuar o s calculos de acordo com a varivel que falta preencher.. class Omh{ function ETens(){ global $P ; global $R ; global $V ; global $I ; //tensao if($V == 0 and $R <> 0 and $I <> 0){ $V = $R * $I; echo "<h3><i> A tensão é " . $V . " </i></h3>"; } ... e tenho um form onde eu insiro so dados para a verificaçao e execuçao dos calculos, echo "<body bgcolor='666666'> <form action='heii.php' method ='post'> <big><i>Potência .: </i></big><br> <input name = 'valP' type='text' value=''style=width:200px;height:40px;font-size:30px;color:gray;><br> <i><big>Resistência .:</big></i><br> <input name = 'valR' type='text' value=''style=width:200px;height:40px;font-size:30px;color:gray;><br> <i><big>Tensão .:</big><i><br> <input name = 'valV' type='text' value=''style=width:200px;height:40px;font-size:30px;color:gray;><br> <i><big>Corrente .:</big><i><br> <input name = 'valI' type='text' value=''style=width:200px;height:40px;font-size:30px;color:gray;><br><br> <input name = sub type='submit' Value='Calcular' style=width:200px;height:40px;font-size:18px;font-style:italic;font-family:impact> </form> </body>"; ?> O problema é o seguinte, Gostaria de colocar as variaveis globais que estao em ETens para serem usadas em toda class Ohm, para não prescisar reescreve-las, POrém ao coloca-las no escopo da class da erro, como posso resolver isso ? Desde já agradeço. Compartilhar este post Link para o post Compartilhar em outros sites
shini 318 Denunciar post Postado Março 8, 2012 tente: public $p; public $r; ... qual erro ocorre? Compartilhar este post Link para o post Compartilhar em outros sites
icaro_ 0 Denunciar post Postado Março 8, 2012 <?php class Omh{ public $P ; public $R ; public $V ; public $I ; function ETens(){ /* global $P ; global $R ; global $V ; global $I ;*/ //tensao if($this->V == 0 and $this->R <> 0 and $this->I <> 0){ $this->V = $this->R * $this->I; echo "<h3><i> A tensão é " . $this->V . " </i></h3>"; } else if($this->V == 0 and $this->P <> 0 and $this->R <> 0){ $this->V = sqrt($this->P * $this->R); echo "<h3><i> A tensão é " . $this->V . " </i></h3>"; } O php nao encontra o s valores para calcular, é como se as variaveis nao fossem encontradas pela class , ou como se os valores nao fossem setados nas variaveis.. Compartilhar este post Link para o post Compartilhar em outros sites
Vinicius Rangel 208 Denunciar post Postado Março 8, 2012 tente definir um valor para elas <?php class Omh{ public $P = 0; public $R = 0; public $V = 0; public $I = 0; function ETens(){ /* global $P ; global $R ; global $V ; global $I ;*/ //tensao if($this->V == 0 and $this->R <> 0 and $this->I <> 0){ $this->V = $this->R * $this->I; echo "<h3><i> A tensão é " . $this->V . " </i></h3>"; } else if($this->V == 0 and $this->P <> 0 and $this->R <> 0){ $this->V = sqrt($this->P * $this->R); echo "<h3><i> A tensão é " . $this->V . " </i></h3>"; } Compartilhar este post Link para o post Compartilhar em outros sites
shini 318 Denunciar post Postado Março 8, 2012 public function ETens(){ .... } Compartilhar este post Link para o post Compartilhar em outros sites
icaro_ 0 Denunciar post Postado Março 8, 2012 GGalera deu certo aqui .. foi um pequeno erro de Orientação a OBjetos... Muito Obrigado pelas dicas.. Foram de grande Valia.. Até a proxima... Compartilhar este post Link para o post Compartilhar em outros sites
shini 318 Denunciar post Postado Março 8, 2012 resolveu como? Compartilhar este post Link para o post Compartilhar em outros sites
icaro_ 0 Denunciar post Postado Março 8, 2012 resolveu como? Criei uma funçao para buscar os valores no form... class ohm{ public $R; public $V; public $I; public $P; public function Ini(){ if(isset($_POST)){ $this->R =($_POST['valR']); $this->V =($_POST['valV']); $this->I =($_POST['valI']); $this->P =($_POST['valP']); } ... Agora ele encontra os valores aos quais eu digito no input´s :yay: e Joga nas funçoes que calculam o result...hehe Muito Obrigado Shini .. até a Proxima. Compartilhar este post Link para o post Compartilhar em outros sites