title: How to check if a function inside a class, that is inside another class exists?
body: <p>i have a function inside a Class that is inside another, this way i can organize all my 'module's engines' in different folders and call they functions.</p>
  
  <p>For example, i have a module called '<strong>mdnewsletter</strong>', that <strong>module has other classes inside</strong> like: 'setting', 'newsletter', etc.</p>
  
  <p>Normally, if i wan't to get the newsletter vars with id '5' i do this:</p>
  
  <pre><code>$res = $mdnewsletter-&gt;newsletter-&gt;get(5);
  if($res===false) { /* error handler here */ }
  
  /* otherwise, the code here */
  </code></pre>
  
  <p>But now i have a module called 'mdapi'. The propose of this module is to <strong>securely</strong> load another module's engine and execute commands only for modules.</p>
  
  <p>My question is on this code snippet:</p>
  
  <pre><code>            $response = @eval($eval);
              if($response===false &amp;&amp; ( $error = error_get_last() )){
                  $this-&gt;error[] = "mdapi-&gt;exec() | A função fornecida não é uma função válida";
                  $can_exec = false;
                  $eval = '';
                  $response = false;
              };
  </code></pre>
  
  <p>As i get the execution string has <strong>'mdnewsletter->newsletter->get'</strong> and arguments in other var, i can't use <code>method_exists()</code>. I really prefer to read the parse error code.</p>
  
  <p>If an parse error occurs, the php code will hang and i can't inform the other side that the code is bad or an error occurred.</p>
  
  <p>How can i fix this?</p>
  
  <p>EDIT:
  Based on <code>Oktopus</code> answer, i've wrote a code that dynamically checks all the objects behind the function and then it test the function with last object, something like this:</p>
  
  <pre><code>            // Avaliar se a primeira parte é uma class e os restantes funcoes
              $tmp = explode ('-&gt;', $tmp);
  
              // Verificar se são objectos até à função (ultima string)
              $obj = $$tmp[0];
              for($i=0;$i&lt;count($tmp)-1;$i++){
                  if($i!=0){
                      $obj = $obj-&gt;$tmp[$i];
                  }
                  if(!is_object($obj)){
                      $this-&gt;error[] = "mdapi-&gt;exec() | A variavel '".$tmp[$i]."' não é um objecto!";
                      $can_exec = false;
                      $eval = '';
                      $response = false;
                  }
              }
  
              // Verificar se a ultima variavel é uma função no ultimo objecto
              if(!is_callable(array($obj, $tmp[count($tmp) - 1]))){
                  $this-&gt;error[] = "mdapi-&gt;exec() | A função pedida não foi encontrada no ultimo objecto!";
                  $can_exec = false;
                  $eval = '';
                  $response = false;
              }
  </code></pre>