How to use method_exist () [closed]

0

How do you find a file to handle this?

    
asked by anonymous 28.01.2016 / 00:23

1 answer

2

I do not understand the question very well, but here's what is the function and how to use it.

The method_exists () function only checks if a method exists:

Description:

bool method_exists ( object $object , string $method_name )
  • Returns bool ( true if method was found and false if not);
  • Get an object (in case it would be your class);
  • You also get a string (with the method name);

Definition:

if(method_exists('MinhaClasse','MeuMetodo')) {
    echo "existe";
} else {
    echo "não existe";
}

Example :

<?php
    $directory = new Directory('.');
    var_dump(method_exists($directory,'read')); //retorna true pois existe o método read na classe de diretório
?>

the same can see it done like this:

<?php
    var_dump(method_exists('Directory','read'));
?>

Example:

<?php
    class A {
        public function FUNC() {
            echo '*****'; 
        }
    }

    $a = new A();
    $a->func(); // printa *****
    var_dump(method_exists($a, 'func')); // retorna bool(true) pois existe tal método
?>

See more: PHP documentation: method_exists ()

    
28.01.2016 / 00:43