Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wywołanie fukcji z klasy $klasa->funkcja1('value')->funkcja2('value')
gothye
post
Post #1





Grupa: Zarejestrowani
Postów: 702
Pomógł: 65
Dołączył: 16.03.2009

Ostrzeżenie: (0%)
-----


Witam

chce przepisać swoją klasę do obsługi SQL w sposób jaki jest wykorzystywane w Zen

lecz niewiem w jaki sposób zadeklarować dane w klasie abym mógł wykonywać w ten sposób obsługę :

  1.  $users = $sql->select('COUNT(*)')->where('user = 1')->order('ASC');

   


Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
gothye
post
Post #2





Grupa: Zarejestrowani
Postów: 702
Pomógł: 65
Dołączył: 16.03.2009

Ostrzeżenie: (0%)
-----


więc napisałem coś takiego :

  1. class test
  2. {
  3. function __construct()
  4. {
  5.  
  6. }
  7.  
  8. function __set($name,$value)
  9. {
  10. $this->name = $value ;
  11. }
  12.  
  13. function __get($name)
  14. {
  15. return $this->name ;
  16. }
  17.  
  18. public function select($select)
  19. {
  20. return 'SELECT '.$select ;
  21. }
  22.  
  23. function from($table)
  24. {
  25. return $this ;
  26. }
  27.  
  28. function where($where)
  29. {
  30. return 'WHERE '.$where ;
  31. }
  32.  
  33. function order($type)
  34. {
  35.  
  36. }
  37.  
  38. function __destruct()
  39. {
  40.  
  41. }
  42.  
  43. }
  44.  
  45. $test = new test ;
  46. echo $test->select('COUNT(*)')->from('users')->where('User=2');
 


i dostaję :

Fatal error: Call to a member function from() on a non-object in /web/test2.php on line 48

pomijam narazie validacje argumentów w fukcjach (IMG:style_emoticons/default/sad.gif)

Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.06.2026 - 09:13