Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> {<|?|>} Wywoływanie klasy z argumentami..., ...z nieznaną ilością argumentów?...
ignition
post
Post #1





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 14.06.2004

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


Chciałbym wywołać klasę z nie określoną ilością argumentów (po przecinku:P), ale nie znalazłem żadnej funkcji, która by to zrobiła. Zrobiłem więc coś takiego:
  1. <?php
  2. $classValue = &#092;"lato, jesień, zima, wiosna\";
  3. $v = explode( ',', $classValue );
  4. $class = new jakasklasa( @$v[0], @$v[1], @$v[2], @$v[3], @$v[4], @$v[5], @$v[6], @$v[7], @$v[8], @$v[9] );
  5. ?>


...ale to ^ mi się za bardzo nie podoba. Czy da się to jakoś krócej zrobić??
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
ignition
post
Post #2





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 14.06.2004

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


Czy dało by się zrobić o coś takiego:
  1. <?php
  2.  
  3. class a
  4. {
  5. function __construct( $a, $b, $c, $d )
  6. {
  7. print &#092;"$a<BR>$b<BR>$c<BR>$d\";
  8. }
  9.  
  10. function test()
  11. {
  12. print 'test';
  13. }
  14. }
  15.  
  16. class blabla
  17. {
  18. public $cValue = 'lato, jesień, zima, wiosna';
  19.  
  20. function __construct()
  21. {
  22.  $jakasNazwaKlasyKtóraBędzieSięZmieniać = $this->classValue( $this->cValue, a);
  23. }
  24.  
  25. function classValue( $classValue, $className )
  26. {
  27. $arrValues = explode( ', ', $classValue );
  28.  
  29. $strCommand = 'new'.&#092;" $className \".'( ';
  30. foreach( $arrValues as $strValue )
  31. {
  32. $strCommand .= ''' . $strValue . '', ';
  33. }
  34. $strCommand = substr( $strCommand, 0, -2 ) . ' );';
  35.  
  36. return eval( $strCommand );
  37. }
  38. } 
  39.  
  40. ?>

...klasa się ładuje, ale nie wiem kto jest obiektem klasy;

Ten post edytował ignition 14.10.2004, 11:17:26
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: 4.10.2025 - 16:23