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

  • SEARCH
  • Home
  • 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 6926647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:56:44+00:00 2026-05-27T10:56:44+00:00

I have the following code; what should be added to the decorator class to

  • 0

I have the following code; what should be added to the decorator class to pass the check of method_exists()? In real task I can’t change the function that calls method_exists().
Also any idea how to cheat ‘get_class_methods()’ and ‘get_class_vars()’?

class real {
    function __construct($arg1,$arg2)
    {

    }

    function test()
    {
        echo "test output\n";
    }
}

class decorator
{
    protected $real;

    function __construct()
    {
        eval('$this->real=new real('.implode(',',func_get_args()).');');
    }

    function __call($method,$args)
    {
        echo "called $method\n";
        $ret=call_user_func_array(array($this->real, $method), $args);
        return $ret;
    }

    public function __isset($name)
    {
        echo "isset $name\n";
    }
}
//-----Can't change below
$r=new decorator(1,2);
if (!method_exists($r,'test')) {die ("method 'test' does not exist, Fail :(\n");}
echo $r->test();

Any ideas ? (I’m thinking of generating a wrapper class by eval())

  • 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-27T10:56:45+00:00Added an answer on May 27, 2026 at 10:56 am

    This answer is extremely simple:

    Make the decorator class extend the real class

    <?php
    class real {
        function __construct() {
            var_dump( func_get_args());
        }
        protected function test(){
            echo "test output\n";
        }
    }
    class decorator extends real{
        function __construct(){
            parent::__construct( func_get_args());
        }
    
        function __call($method,$args){
            echo "called $method\n";
            return call_user_func_array( array( 'parent', $method), $args);
        }
    
        public function __isset($name) {
            echo "isset $name\n";
        }
    }
    //-----Can't change below
    $r = new decorator(1,2);
    if(!method_exists($r,'test')) {die ("method 'test' does not exist, Fail :(\n");}
    echo $r->test();
    

    This is a much better design, and it works!

    To better solve the underlying problem of inspecting a proprietary encoded program, I also suggest the use of XDebug’s execution_trace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which should put programs startable in Bash. if [
I have the following code that seems like it should set my insertParameter but
I have the following code, that should remove the access of users from a
I have the following code, that in my head should create a new row
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following code which should make drawFrame be called every frame but
I have the following jQuery code: $('.save').submit(function(e){ var formElement = $(this); var data =
I have the following code //check out the tags, if it allready exist update
Update: I've added the following code: function TSettingsForm.AppDataPath: string; //CSIDL_APPDATA Individual user Data //CSIDL_COMMON_APPDATA
I have the following code. I want to add/remove check-box values to an array

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.