dziś po raz 1szy chciałem napisać coś obiektowo. Pewnie wyszło mi to trochę pseudo obiektowo ale co tutaj mam nie tak.
najpierw klasa
<?php class prostokat { public $bokA, $bokB, $wynik; public function setBokA($bokA) { $this -> bokA = $bokA; } public function setBokB($bokB) { $this -> bokB = $bokB; } public function setWynik() { $this -> wynik = $wynik; } // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ public function getAction() { switch ( $_POST['dzialanie'] ) { case '+': return '+'; break; case '-': return '-'; break; case '*': return '*'; break; case '/': return '/'; break; default: return 0; } } public function obliczIloczyn($bokA, $bokB) { $this -> wynik = $this -> bokA . getAction() . $this -> bokB; //$this -> wynik = $this -> bokA * $this -> bokB; return '---------------<br />Wynik = ' . $this -> wynik; } public function showBokA() { return 'Bok a = ' . $this -> bokA; } public function showBokB() { return 'Bok b = ' . $this -> bokB; } public function validateData() { { return 1; }else { return 0; } } } // end of class ?>
i uzycie
<form method="POST" action=""> Podaj bok a: <input type="text" name="bok1" /> Podaj bok b: <input type="text" name="bok2" /> <br /><br /> Dzialanie: <br /> <input type="radio" name="dzilanie" value="+" />dodaj <br /> <input type="radio" name="dzilanie" value="-" />odejmij <br /> <input type="radio" name="dzilanie" value="*" />pomnoz <br /> <input type="radio" name="dzialanie" value="/" />podziel <br /><br /> <input type="submit" value="OK" /> </form> <?php include ('_class.php'); $square = new prostokat(); $square -> setBokA( $_POST['bok1'] ); $square -> setBokB( $_POST['bok2'] ); if ( $square -> validateData() == 1 ) { ?>
i dostaje taki blad
Fatal error: Call to undefined function getAction() in C:\wamp\www\oop\_class.php on line 52
sama funkcja zwracająca znak działa...
pozdrawiam