undefined class constant (function)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello;

I am trying to call either of two defined functions in a class def that
are assigned to associative array items.

$_proc = [];
$_proc['sync'] = self::listSync;
$_proc['async'] = self::listAsync;
return $_proc[$_type]($_fileLst);

"Fatal error: undefined class constant listSync...."

private function listSync(<arg>)
          {
           // code, return result;
          }

private function listAsync(<arg>)
          {
           // code, return result;
          }

I thought that if I did it like:
$_proc['sync'] = self::listSync()

self::listSync would be run and $_proc['sync'] would contain
what is returned.

So, trying to avoid a round of if/else if or switch block, how would I 
do this? 

I thought that this might work like javascript (I know javascript is a different language
but is mostly translatable to php). In js a function can be assigned to a variable and
called via the variable at a later time.

While composing this it might not be a bad idea that $_proc[<label>] would
contain the result of the function. So I probably answered my own question
for the task at hand. But allowing the $_proc items to hold function result
means that both function would have to be run so a statement like
return $_proc[$_type];
would work.

For future reference, how would I assign a function to a variable for delayed
execution in this situation?

Thanks for time and attention
JK.
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux