Jim Bailie Posted September 18, 2023 Share 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. Link to comment Share on other sites More sharing options...
Robin S Posted September 18, 2023 Share 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 Link to comment Share on other sites More sharing options...
Jim Bailie Posted September 18, 2023 Author Share Posted September 18, 2023 @Robin S Interesting. Looks like another area to brush up on. Thanks again! Link to comment Share on other sites More sharing options...
da² Posted September 19, 2023 Share 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 Link to comment Share on other sites More sharing options...
Jim Bailie Posted September 19, 2023 Author Share 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. Link to comment Share on other sites More sharing options...
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