Web lists-archives.com

Re: Function name must be a string error




I am using php v 5.5x (included in Apache installation on Mac Yosemite.

What I am finding after testing all the input args for valid values is that
requiring a file with an anonymous function set to a variable will allow
the function to be called by the variable name: in this case $_code.
But if I assign the $_code variable (containing the function def) to a 
static member variable, I get the error when the static member variable is 
use to invoke the function.

So, that means that I should require the file just prior to actually calling the code it
contains. BUT, that will mean errors regarding calling require for the same file more
than once, because this is a recursive method.

So, I should take a whole other approach and abandon the idea of requiring code 
files for execution on demand. I can put all the code in private methods in the class def
itself.

Thanks for attention;
Jeff k
> On Dec 4, 2018, at 3:30 AM, Enno Woortmann <enno.woortmann@xxxxxx> wrote:
> 
> Hi Jeff,
> 
> try
> 
> (self::$_proc)(/*args*/);
> 
> This will work if you are using PHP >= 7.0
> 
> Additional ways are described in: https://stackoverflow.com/questions/7067536/how-to-call-a-closure-that-is-a-class-variable
> 
> regards,
> 
> Enno
> 
> Am 04.12.2018 um 02:44 schrieb Jeffry Killen:
>>> On Dec 3, 2018, at 5:19 PM, Aziz Saleh <azizsaleh@xxxxxxxxx> wrote:
>>> 
>>> var_dump(self::$_proc) before the function call, what do you get?
>> 
>> object(Closure)#2 (2) {
>>   ["this"]=>
>>   object(_FS_RECURSOR)#1 (0) {
>>   }
>>   ["parameter"]=>
>>   array(4) {
>>     ["$_src"]=>
>>     string(10) "<required>"
>>     ["$_type"]=>
>>     string(10) "<required>"
>>     ["$_list"]=>
>>     string(10) "<required>"
>>     ["$_localArgs"]=>
>>     string(10) "<required>"
>>   }
>> }
>> 
>>> On Mon, Dec 3, 2018 at 8:01 PM Jeffry Killen <jekillen@xxxxxxxxxxx> wrote:
>>> Hello again;
>>> 
>>> I have solved this before. But it has been too long ago.
>>> I don't remember what the fix was;
>>> 
>>> file with function definition:
>>> 
>>> $_funct = function(/*args*/){ // code}
>>> 
>>> class def:
>>> 
>>> private static $_proc = '';
>>> 
>>> __construct() requires file with $_funct definition
>>> and assigns it to self::$_proc
>>> 
>>> require(/*file with funct definition*/)
>>> 
>>> self::$_proc = $_funct;
>>> 
>>> later in $_POST processing the function is called:
>>> 
>>> self::$_proc(/*args*/) // ->  Function name must be a string
>>> 
>>> There are actually more steps to this, but it would require
>>> a lot of code reproduced here for it to make sense. This abstraction
>>> is about as simple as I can represent it.
>>> 
>>> In the processing the self::$_proc function is being called under
>>> different circumstances. The error occurs on the first time it is
>>> called. So It appears that it is not a case where one particular
>>> line has a problem and the others don't.
>>> 
>>> This has been working elsewhere in testing in the same project.
>>> 
>>> I google the error and didn't get listings for the same type of issue.
>>> 
>>> Thanks for time and attention;
>>> Jeff K
>>