Accessing a function in a class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Accessing a function in a class

Post 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?
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

OO callbacks are arrays:

Code: Select all

array('ClassName', 'staticMethod');
or
array($object, 'method');
for php4, the latter needs a reference.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Is there a function_exists() for callbacks?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You might be looking for method_exists.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

That led me to is_callable() which is what I was looking for. Thanks. ^_^
Post Reply