Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/07/2013, 10:22
Avatar de carlos_belisario
carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Llamar metodo con variable

Yo jugando un poco con reflection

Código PHP:
Ver original
  1. <?php
  2. class Test
  3. {
  4.     public function method1($name)
  5.     {
  6.         echo "hola $name";
  7.     }
  8.     public function method2()
  9.     {
  10.         try {
  11.             $method = 'method1';
  12.             $r = new ReflectionClass($this);
  13.             $r->getMethod($method)->invoke($this, 'carlos');
  14.         } catch(Exception $e) {
  15.             echo $e->getMessage();
  16.         }
  17.     }
  18. }
  19.  
  20. $a = new Test();
  21. $a->method2();

a lo mejor me regañan por ahí
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way