note 97890 added to functions.arguments

From: Date: Fri, 14 May 2010 00:19:17 +0000
Subject: note 97890 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-169228@lists.php.net to get a copy of this message
This may be helpful when you need to call an arbitrary function known only at runtime: You can call a function as a variable name. <?php function foo(){ echo"\nfoo()"; } function callfunc($x, $y = '') { if( $y=='' ) { if( $x=='' ) echo "\nempty"; else $x(); } else $y->$x(); } class cbar { public function fcatch(){ echo "\nfcatch"; } } $x = ''; callfunc($x); $x = 'foo'; callfunc($x); $o = new cbar(); $x = 'fcatch'; callfunc($x, $o); echo "\n\n"; ?> The code will output empty foo() fcatch ---- Server IP: 69.147.83.197 Probable Submitter: 174.29.159.128 ---- Manual Page -- http://www.php.net/manual/en/functions.arguments.php Edit -- https://master.php.net/note/edit/97890 Del: integrated -- https://master.php.net/note/delete/97890/integrated Del: useless -- https://master.php.net/note/delete/97890/useless Del: bad code -- https://master.php.net/note/delete/97890/bad+code Del: spam -- https://master.php.net/note/delete/97890/spam Del: non-english -- https://master.php.net/note/delete/97890/non-english Del: in docs -- https://master.php.net/note/delete/97890/in+docs Del: other reasons-- https://master.php.net/note/delete/97890 Reject -- https://master.php.net/note/reject/97890 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169228) next »