fork download
  1. <?php
  2. class MinhaClasse {
  3. var $foo = 'ola mundo';
  4. var $bar = 'teste para o stack';
  5. public function index($fn = a) {
  6. echo $this->$fn(); // <-- é isso que eu quero
  7. }
  8. private function a() {
  9. return $this->foo;
  10. }
  11. private function b() {
  12. return $this->bar;
  13. }
  14. }
  15. $classe = new MinhaClasse();
  16. $classe->index();
  17. $classe->index(b);
  18.  
  19. //https://pt.stackoverflow.com/q/105037/101
Success #stdin #stdout #stderr 0.02s 24464KB
stdin
Standard input is empty
stdout
ola mundoteste para o stack
stderr
PHP Warning:  Use of undefined constant a - assumed 'a' (this will throw an Error in a future version of PHP) in /home/HWb8ms/prog.php on line 5
PHP Warning:  Use of undefined constant b - assumed 'b' (this will throw an Error in a future version of PHP) in /home/HWb8ms/prog.php on line 17