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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:27:28+00:00 2026-06-15T09:27:28+00:00

I need to organize some kind of access control to object methods when it

  • 0

I need to organize some kind of access control to object methods when it is used in different contexts (API’s in my system). Here is code example:

    class A
    {
      public function doA(){}
      public function doB(){}
    }

    class APIAClient
    {
      public function getA()
      {
        return new A();
      }
    }

    class APIBClient {
      public function getA()
      {
        return new A();
      }
    }

In APIAClient object A should have both methods doA() and doB(), but in APIBClient should not have doB() method.

For now I’ve implemented APIBClientAProxy (which is returned by APIBCleint->getA())

   class APIBClientAProxy
   {
     private $a = new A;
     public function doA()
     {
       $this->a->doA()
     }
   }

But may be there is a better pattern for solving my problem, without using a additional proxy object for every context (i.e. API). I’m thinking about magic __call method with list of allowed methods in particular context, but magic calls is hard do document and documentation is the big point in my app (API’s should be documented well)

Thanks!

  • 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-06-15T09:27:29+00:00Added an answer on June 15, 2026 at 9:27 am

    Instead of inheritance you can use composition through traits (introduced in PHP 5.4).

    First define traits

    trait A {
      public function doA() {
        // do something here
      }
    }
    
    trait B {
      public function doB() {
        // do something here
      }
    }
    

    then use those traits in your class declaration

    class APIAClient {
      use A, B
    
    }
    
    class APIBClient {
      use A
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some regular expressions help. So far I have my code working to allow
i need help how to organize nodes of drupal cms. i have three kind
Okay, I need some solid OOP advice. Here's the setup: I have a player
I need some advice regarding how to organize my data for effective and fast
I need some recommendation on how to organize Eclipse Plugin/Feature/Update Site projects in SVN.
I need to organize some simple security in a class depends on value of
I use ajaxToolkit:TabContainer to organize page contents. Some times, I need to hide some
I just need a little help how to organize my code. This is not
I need to organize windows service which should interacts with applications next way: Application
I need to organize cache in mySql database for address - coordinates. What is

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.