CodeIgniter Forums
function exists - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: function exists (/showthread.php?tid=9287)



function exists - El Forum - 06-20-2008

[eluser]dbashyal[/eluser]
how can i check if function exists in CI

i did
Code:
if(function_exists($this->direction))

also,
Code:
if(function_exists('direction'))

none of them worked

on the previous one it says undefined property direction

second one returns false

i searched the forum couldn't find the solution.

i am not that much into classes, so get hard time, sometimes


function exists - El Forum - 06-20-2008

[eluser]mironcho[/eluser]
For checking if a particular method exists in some object, try to use method_exists() function:


http://php.net/method_exists


function exists - El Forum - 06-20-2008

[eluser]Huan[/eluser]
Yes, you could try

if (method_exists($this->somename, some_function))


function exists - El Forum - 06-20-2008

[eluser]dbashyal[/eluser]
Thanks it worked

Code:
function _remap($method)
    {
        $method = str_replace('-', '_', $method);
        
        if (method_exists($this,$method)) {
            $this->$method();
        } else {
            $this->index();
        }
    }

may not be the best method that i am trying to do, but it still works. Smile