Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5941435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:06:35+00:00 2026-05-22T16:06:35+00:00

i have a function inside a Class that is inside another, this way i

  • 0

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.

For example, i have a module called ‘mdnewsletter‘, that module has other classes inside like: ‘setting’, ‘newsletter’, etc.

Normally, if i wan’t to get the newsletter vars with id ‘5’ i do this:

$res = $mdnewsletter->newsletter->get(5);
if($res===false) { /* error handler here */ }

/* otherwise, the code here */

But now i have a module called ‘mdapi’. The propose of this module is to securely load another module’s engine and execute commands only for modules.

My question is on this code snippet:

            $response = @eval($eval);
            if($response===false && ( $error = error_get_last() )){
                $this->error[] = "mdapi->exec() | A função fornecida não é uma função válida";
                $can_exec = false;
                $eval = '';
                $response = false;
            };

As i get the execution string has ‘mdnewsletter->newsletter->get’ and arguments in other var, i can’t use method_exists(). I really prefer to read the parse error code.

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.

How can i fix this?

EDIT:
Based on Oktopus 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:

            // Avaliar se a primeira parte é uma class e os restantes funcoes
            $tmp = explode ('->', $tmp);

            // Verificar se são objectos até à função (ultima string)
            $obj = $$tmp[0];
            for($i=0;$i<count($tmp)-1;$i++){
                if($i!=0){
                    $obj = $obj->$tmp[$i];
                }
                if(!is_object($obj)){
                    $this->error[] = "mdapi->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->error[] = "mdapi->exec() | A função pedida não foi encontrada no ultimo objecto!";
                $can_exec = false;
                $eval = '';
                $response = false;
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:06:36+00:00Added an answer on May 22, 2026 at 4:06 pm

    I won’t go in the “it may be insecure thing”, but here is how you could do it :

    //Exemple string : 
    $parts = explode ('->', "object->property->testCall");
    //How to test if it's callable
    if (is_object($$parts[0]->$parts[1])){
        echo "it's an object";
        if (is_callable(array($$parts[0]->$parts[1], $parts[2]))){
            echo "it's callable";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function inside a class that returns a reference to a member
I have this code snippet inside a function that checks if an object exists
I have a couple of functions inside a class that essentially do the same
I have the following function defined inside my linked list class. The declaration in
I have a function that is often called inside of other functions, and I'd
If I derive a class from another one and overwrite a function, I can
soooo i have this function that prints one of 5 random texts ON an
I have a library-provided function that runs a callback after some processing. Inside that
Is is safe to instantiate a class inside a member function of that class?
How can I handle static varibles inside my server session? I have 30 different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.