Page 1 of 1

Accessing a function in a class

Posted: Mon Jun 25, 2007 7:02 pm
by superdezign
I want to use preg_replace_callback() which works fine unless I'm trying to use a function from a class. This is due to me not being able to get the function, not even through function exists.

Code: Select all

echo function_exists("FunctionName") ? 'yes' : 'no';
echo function_exists("self::FunctionName") ? 'yes' : 'no';
echo function_exists("ClassName::FunctionName") ? 'yes' : 'no';
All of those echo 'no.' Anyone know what I'm doing wrong?

Posted: Mon Jun 25, 2007 7:17 pm
by stereofrog
OO callbacks are arrays:

Code: Select all

array('ClassName', 'staticMethod');
or
array($object, 'method');
for php4, the latter needs a reference.

Posted: Mon Jun 25, 2007 7:48 pm
by superdezign
Is there a function_exists() for callbacks?

Posted: Mon Jun 25, 2007 8:03 pm
by volka
You might be looking for method_exists.

Posted: Mon Jun 25, 2007 8:10 pm
by superdezign
That led me to is_callable() which is what I was looking for. Thanks. ^_^