note 123706 added to functions.variable-functions

From: Date: Tue, 19 Mar 2019 11:28:36 +0000
Subject: note 123706 added to functions.variable-functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-210412@lists.php.net to get a copy of this message
While the documentation suggests that the use of a constant is similar to the use of a variable, there is an exception regarding variable functions. You cannot use a constant as the function name to call a variable function. const DEBUGME ='func'; function func($s) { echo $s. "\n"; } DEBUGME('abc'); // results in a syntax error $call = DEBUGME; $call('abc'); // does the job But you can use a constant as an argument to a function. Here's a simple workaround when you need to call a variable constant function: function dynamic($what, $with) { $what($with); } dynamic(DEBUGME, 'abc'); This makes sense to me to hide API's and/or long (complicated) static calls. Enjoy! ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.194 (proxied: 88.74.12.66) ---- Manual Page -- http://php.net/manual/en/functions.variable-functions.php Edit -- https://master.php.net/note/edit/123706 Del: integrated -- https://master.php.net/note/delete/123706/integrated Del: useless -- https://master.php.net/note/delete/123706/useless Del: bad code -- https://master.php.net/note/delete/123706/bad+code Del: spam -- https://master.php.net/note/delete/123706/spam Del: non-english -- https://master.php.net/note/delete/123706/non-english Del: in docs -- https://master.php.net/note/delete/123706/in+docs Del: other reasons-- https://master.php.net/note/delete/123706 Reject -- https://master.php.net/note/reject/123706 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#210412) next »