Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Alias dla metody
mkulas
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 26.02.2013

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


Witam wszystkich.
Piszę własnego frameworka i chciałby zrobić alias z metody.
Przeszukałem manuala PHP i nic nie znalazłem.

  1. function funkcja ()
  2. {
  3. echo 'funkcja';
  4. }
  5.  
  6. class klasa
  7. {
  8. public function metoda ($parametr)
  9. {
  10. echo 'metoda';
  11. }
  12. }
  13.  
  14. // powiedzmy ze to alias dla funkcji
  15. function alias_dla_funkcji ($parametr)
  16. {
  17. return funkcja ($parametr);
  18. }
  19.  
  20. function alias_dla_metody ($parametr)
  21. {
  22. // i tutaj chcialbym zrobic alias dla metody o nazwie funkcja ze zwyklej funkcji
  23. }
  24.  


Ten post edytował mkulas 27.02.2013, 09:24:52
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Twoje rozwiązanie jest bezsensowne (pomijając tego globala) skoro i tak musisz pobrać obiekt.

  1. <?php
  2.  
  3. class A {
  4.  
  5. public function aaa() {
  6.  
  7. echo "hej";
  8. }
  9. }
  10.  
  11.  
  12. function alias($className, $method) {
  13.  
  14. $class = new $className();
  15. call_user_func(array($class, $method));
  16. }
  17.  
  18. alias('A','aaa');


lub zwyczajnie podać obiekt jako argument funkcji
  1. <?php
  2.  
  3. class A {
  4.  
  5. public function aaa() {
  6.  
  7. echo "hej";
  8. }
  9. }
  10.  
  11.  
  12. function alias($class, $method) {
  13.  
  14. $class -> $method();
  15. }
  16.  
  17. alias(new A(),'aaa');
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: 12.10.2025 - 11:09