Jim Bailie Posted September 18, 2023 Posted September 18, 2023 This example from https://www.php.net/manual/en/functions.variable-functions.php does not work in PW or any script bootstrapping the same (namespacing?). function foo() { echo "In foo()<br />\n"; } $func = 'foo'; $func(); // This calls foo() I'm sure there is an explanation for this, but I haven't been able to discover that as of yet.
Robin S Posted September 18, 2023 Posted September 18, 2023 2 hours ago, Jim Bailie said: namespacing? Yes, it's because of the ProcessWire namespace. Add it when setting the function name to your variable: $func = 'ProcessWire\foo'; 1
Jim Bailie Posted September 18, 2023 Author Posted September 18, 2023 @Robin S Interesting. Looks like another area to brush up on. Thanks again!
da² Posted September 19, 2023 Posted September 19, 2023 It's particular to call a function by a string. 99.99 % of the time you have better to do. 1
Jim Bailie Posted September 19, 2023 Author Posted September 19, 2023 @da² It certainly is peculiar; disdainful even. But this is that one basis point case where it's simply a convenience to show/format a bunch of legacy content from an old database.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now