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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:35:03+00:00 2026-05-23T18:35:03+00:00

I have an API for interacting with my web app, defined by a class.

  • 0

I have an API for interacting with my web app, defined by a class. Each publicly accessible method needs to have authentication done before running. Rather than putting the same line over and over in each method, I’d like to use the magic __call function. However, it will only work on private or protected methods, and mine need to be public in order to work with Zend_Json_Server.

class MY_Api
{
  public function __call($name, $arguments)
  {
    //code here that checks arguments for valid auth token and returns an error if false
  }

  public function myFunction($param1, $param2, $param3)
  {
    //do stuff when the user calls the myFunction and passes the parameters
    //this function must remain public so that Zend_Json_Server can parse it
    //but I want it intercepted by a magic method so that the authentication
    //can be checked and the system bails before it even gets to this function.
  }
}

Is it possible to hook into these public functions and possibly cancel their execution before they are called?

  • 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-23T18:35:04+00:00Added an answer on May 23, 2026 at 6:35 pm

    __call actually works for all methods, including public. However, the reason it won’t work if the public method already exists, is because code outside your class can already access the public members. __call is only invoked for members which aren’t accessible by the calling code.

    As far as I know there are really no options to do what you’re looking for, except by using some kind of a decorator pattern:

    class AuthDecorator {
        private $object;
    
        public function __construct($object) {
            $this->object = $object;
        }
    
        public function __call($method, $params) {
            //Put code for access checking here
    
            if($accessOk) {
                return call_user_func_array(array($this->object, $method), $params);
            }
        }
    }
    
    $api = new MY_Api();
    $decoratedApi = new AuthDecorator($api);
    
    //any calls to decoratedApi would get an auth check, and if ok, 
    //go to the normal api class' function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have a Web API running on Heroku that is constantly writing information
At work we have a web app that we'll need to interface with another
We have three web services ( /a , /b , /c ) where each
I have a web application that is integrating with Twitter's OAuth API. I registered
I'm writing a wrapper class for a third-party web service(SOAP) api. I want to
I am integrating Facebook authentication, registration and app requests with our web app, using
I have written a web API in BaseHTTPServer. It is meant to be used
I want to add user authentication to my restful api that I have created
I have an API that is dependent on certain state information between requests. As
I have an API consisting of ASP.NET webservices callable through GET/POST/SOAP. A new functionality

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.