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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:58:45+00:00 2026-05-17T22:58:45+00:00

Here’s the premise: I have many classes where I need to perform an action

  • 0

Here’s the premise:

I have many classes where I need to perform an action BEFORE any method from any of the classes is called, my solution was to have all of the classes extend a parent class which would define a call() function which would look like:

public function call($method){
    //do the something I need to do before method calls
    $params = func_get_args();
    //remove the $method param from the $params array
    unset($params[0]);
    return $this->__call($method,$params);
}

And then simply call the call method and specify the actual method I wanted to call, that way the method would get called, but inside the call method (which the class inherits from my parent class) I could carry out the action I needed to carry out before the specified method gets called.

This needs to be able to support arguments that could be arrays or strings, so anything that involves imploding an array of arguments will not work (since this would assume all arguments are strings).

I am not sure if what I have above makes sense, and I wanted to check and see if I’m going about this the wrong way or not.

Any ideas/thoughts would be greatly appreciated.

Thanks!

PS: I should note that my description of the situation above makes it sound like the reason the child classes extend the parent is simply for this purpose, in reality there are more reasons (my parent class extends Zend_Db_Table_Abstract and my database models extend the parent).

  • 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-17T22:58:45+00:00Added an answer on May 17, 2026 at 10:58 pm

    __call is called automatically, if it’s defined, whenever you try to call a function that doesn’t exist. That’s why it’s a “magic” method. It seems odd to me to use it directly, rather than in the context for which it is intended. Here, you might as well have named it anything.

    You could definitely use the power of __call to your advantage here. Try naming all the member functions with an underscore before them. So, if you before had $this->print() you would now have $this->_print(). Then, in your __call function, add the underscore and call the function using call_user_func_array(array($this,"_$name"), $params). Now you can call your functions normally (well, without the underscore).

    Still, I wouldn’t suggest using __call except as a convenience. Long-term it is best to just call any code that you want to run directly.

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

Sidebar

Related Questions

Here the scenario is I have many .aspx pages if any page gives error,
Here is my problem : I have a post controller with the action create.
Here is an example: I have the generic type called Account. I wish to
Here is my error(if you need any more info just ask)- Error SQL query:
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here's the basic setup: I have a thin bar at the top of a
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the problem that I am trying to solve. I have two folders
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function

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.