|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-09-19 03:09 UTC] mephtu at yahoo dot com
Description:
------------
I want to be able to execute ad hoc function variables.
Reproduce code:
---------------
<?php
function do_bucket() {
echo 'Hello, world!';
}
$tag = "bucket";
$'do_'.tag();
?>
Expected result:
----------------
Hello, world!
Actual result:
--------------
Error.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 18:00:02 2025 UTC |
That has never worked, not even for variables. All of the following will work fine: $t = 'do_'.$tag; $t(); Your problem is that your syntax is basically impossible. It can not distinguish between: $'do_' . tag(); which might be either something remotely looking like a variable (parse error'd of course) followed by a concatenation operator, followed by a function call to function tag(). OR which might be that you want to concatenate everything together, and THEN execute the function by that name. The thing is, the parser can't differentiate between those two, so it doesn't even try. You can already execute "ad hoc function variables", as long as you use proper syntax. It is unfortunate that something like: ${'do_'.$tag}(); does not work, but instead returns Fatal error: Function name must be a string Anyway, marking as bogus since you already can do this.