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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:51:57+00:00 2026-05-11T00:51:57+00:00

Is there some equivalent of friend or internal in php? If not, is there

  • 0

Is there some equivalent of ‘friend’ or ‘internal’ in php? If not, is there any pattern to follow to achieve this behavior?

Edit: Sorry, but standard Php isn’t what I’m looking for. I’m looking for something along the lines of what ringmaster did.

I have classes which are doing C-style system calls on the back end and the juggling has started to become cumbersome. I have functions in object A which take in object B as a parameter and have to call a method in object B passing in itself as an argument. The end user could call the method in B and the system would fall apart.

  • 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. 2026-05-11T00:51:57+00:00Added an answer on May 11, 2026 at 12:51 am

    PHP doesn’t support any friend-like declarations. It’s possible to simulate this using the PHP5 __get and __set methods and inspecting a backtrace for only the allowed friend classes, although the code to do it is kind of clumsy.

    There’s some sample code and discussion on the topic on PHP’s site:

    class HasFriends {     private $__friends = array('MyFriend', 'OtherFriend');      public function __get($key)     {         $trace = debug_backtrace();         if(isset($trace[1]['class']) && in_array($trace[1]['class'], $this->__friends)) {             return $this->$key;         }          // normal __get() code here          trigger_error('Cannot access private property ' . __CLASS__ . '::$' . $key, E_USER_ERROR);     }      public function __set($key, $value)     {         $trace = debug_backtrace();         if(isset($trace[1]['class']) && in_array($trace[1]['class'], $this->__friends)) {             return $this->$key = $value;         }          // normal __set() code here          trigger_error('Cannot access private property ' . __CLASS__ . '::$' . $key, E_USER_ERROR);     } } 

    (Code proved by tsteiner at nerdclub dot net on bugs.php.net)

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

Sidebar

Related Questions

Is there a Python equivalent of PHP's mysql_real_escape_string ? I'm trying to insert some
Is there some equivalent to PHP mysql_insert_id to fetch the last inserted UUID() primary
Is there some equivalent class for C++1x's std::unique_ptr in the boost libraries? The behavior
This is not a question about putting std::auto_ptr into std::vector. Is there some vector
In .NET you have System.Threading.Thread.IsBackground . Is there some equivalent of this in WinRT/Metro?
Is there some equivalent to jQuery's getScript in Prototype ?
Is there some sort of equivalent of CellMouseEnter from the winforms DataGridView control for
Is there some reason why the Prelude doesn't define the list monad like this?
Is there some equivalent of javascripts indexOf in Velocity? I want to test whether
Is there some equivalent to the StringBuilder.Insert method for use with byte arrays? I

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.