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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:52:13+00:00 2026-05-24T05:52:13+00:00

If a call is made to an undefined method in a class, the magic

  • 0

If a call is made to an undefined method in a class, the magic method __call can intercept the call, so I could handle the situation as I see fit:
http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods

Is there any mechanism provided in php whereby I can do the same thing with functions in global scope.
The point is best illustrated with code:

    <?php
    function return_some_array(){
      $a = array();
      //Do stuff to array
      return array();
    }

    // Now i call the function like so:
    $give_me_array = return_some_array();

    // But sometimes I want the array to not contain zeroes, nulls etc.
    // so I call: 
    $give_me_array_filtered = return_some_array_filtered();

    // But i haven't defined return_some_array_filtered() anywhere.
    // Instead I would like to do something like so: 
    function __magic_call($function_name_passed_automatically){ 
      preg_match('/(.*)_filtered$/', $function_name_passed_automatically, $matches);
      $function_name_that_i_defined_earlier_called_return_some_array = $matches[1];
      if($matches){
        $result = call_user_func($function_name_that_i_defined_earlier_called_return_some_array);
        $filtered = array_filter($result);
        return $filtered;
      }
    }

    //So now, I could call return_some_other_array_filtered() and it would work provided I had defined return_some_other_array().
    //Or even Donkey_filtered() would work, provided I had defined Donkey() somewhere.
    ?>

Is this at all possible?

  • 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-24T05:52:13+00:00Added an answer on May 24, 2026 at 5:52 am

    Not as such.

    If you had made a static method like return_some_array_filtered::go() then you could use PHP5’s autoload() facility to dynamically create the class and method. After creation the call proceeds as usual. You may want to implement callStatic() on that class. Beware dynamically creating a class from scratch (without include()) in PHP is non-trivial.

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

Sidebar

Related Questions

So I have a situation where there is an ajax call made after a
Save one image path in the database... and whenever a call is made to
In my Fortran code I made the following call to the dnrm2 routine: d
I need to call the index of a matrix made using the linspace command,
I have a template I made that sets variables that rarely change, call my
A desktop app (made in Delphi) is started by User A. Let's call it
Does anybody know how to redirect parent page from an ajax call? I made
I am using asp.net mvc with jquery... I have made a json call to
I am having trouble calling a specific function within a class. The call is
Hopefully I've just made a dumb oversight, but I can't figure out why the

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.