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 1080607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:03:34+00:00 2026-05-16T22:03:34+00:00

I found this while searching for how to fake multiple inheritance in PHP (since

  • 0

I found this while searching for how to fake multiple inheritance in PHP (since PHP does not support multiple inheritance directly).

Can I extend a class using more than 1 class in PHP?

Here is the complete code given there:-

class B {
    public function method_from_b($s) {
        echo $s;
    }
}

class C {
    public function method_from_c($s) {
        echo $s;
    }
}

class A extends B
{
  private $c;

  public function __construct()
  {
    $this->c = new C;
  }

  // fake "extends C" using magic function
  public function __call($method, $args)
  {
    $this->c->$method($args[0]);
  }
}


$a = new A;
$a->method_from_b("abc");
$a->method_from_c("def");

The problem
The example given here considers only one parameter for the function C::method_from_c($s). It works fine with one parameter but I have several functions of class C, some having 2, some having 3 parameters like this:-

class C {
    public function method_from_c($one,$two) {
        return $someValue;
    }

    public function another_method_from_c($one,$two, $three) {
        return $someValue;
    }
}

And I do not want to change anything in Class C’s function definition (It must accept those many parameters). E.g. I do not want to use func_get_args() inside my C::method_from_c($s,$two) like this:-

public function method_from_c() 
{

     $args = func_get_args();

     //extract params from $args and then treat each parameter
}

What to do inside the __call() function of class A so that it works. I want to be able to call Class C functions like $obj->method_from_c($one,$two);

Thanks
Sandeepan

  • 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-16T22:03:34+00:00Added an answer on May 16, 2026 at 10:03 pm

    you can use call_user_func_array:

    function __call($method, $args) {
        call_user_func_array(array(&$this->c, $method), $args);
    }
    

    note that this won’t perform as well though.

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

Sidebar

Related Questions

I'm searching a while for this and I can't found something that works for
Spent a while searching on this and found nothing that related directly. I have
While searching the web, I found this code: $apprequest_url =https://graph.facebook.com/ . /apprequests?ids=USERID_1,USERID_2,USERID_3 . &message='INSERT_UT8_STRING_MSG'
While searching for Tutorials on generating random numbers in C I found this topic
While searching for linq conditional where clause, I found this article , the way
While searching for how to do this, I found some vague discussion about different
While searching for an answer to this question I found this sample code which
After a while of searching the internet, I found this piece of code that
While searching for a solution to a python regular expression problem I found this
I found this document on the official ORACLE page while searching for information on

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.