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

  • Home
  • SEARCH
  • 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 699377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:22:46+00:00 2026-05-14T03:22:46+00:00

Is there any way to get the caller function with something else than debug_backtrace()?

  • 0

Is there any way to get the caller function with something else than debug_backtrace()?

I’m looking for a less greedy way to simulate scopes like friend or internal.

Let’s say I have a class A and a class B.

Until now, I’ve been using debug_backtrace(), which is too greedy (IMHO).

I thought of something like this:

<?php

    class A
    {
        public function __construct(B $callerObj) {}
    }

    class B
    {
        public function someMethod()
        {
            $obj = new A($this);
        }
    }
?>

It might be OK if you want to limit it to one specific class, but let’s say I have 300 classes, and I want to limit it to 25 of them?

One way could be using an interface to aggregate:

public function __construct(CallerInterface $callerObj)

But it’s still an ugly code.

Moreover, you can’t use that trick with static classes.

Have any better idea?

  • 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-14T03:22:47+00:00Added an answer on May 14, 2026 at 3:22 am

    You can call debug_backtrace(FALSE), which will then not populate the object index. This will speed it up a little bit, but generally, debug_backtrace is to be avoided in production code, unless your app is software tool where speed is not an issue or when using it for error handling.

    From what I understand, you want to

    • have an implicit reference to the caller available in the callee and
    • outside access to private and protected properties to selected classes.

    Both does not exist in PHP (and breaks encapsulation imho). For a discussion, please see

    • [PHP-DEV] reference caller object and
    • [PHP-DEV] Support for friend classes
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is it possible to run a Python script as a… May 16, 2026 at 9:57 am
  • Editorial Team
    Editorial Team added an answer Use offset = (page - 1) * itemsPerPage + 1. May 16, 2026 at 9:56 am
  • Editorial Team
    Editorial Team added an answer A typical sigmoid curve is the tanh(x) curve. By definition,… May 16, 2026 at 9:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is there any way to get the ID of the element that fires an
Is there any way to use DataContext to execute some explicit SQL and return
Is there a way to get reversed engineered uml diagrams into Omnigraffle? I got
I am testing a function called extractions that operates over any list. extractions ::
I'm trying to find a way to integrate my website, coded using Symfony with
I'm trying to implement some STL-style sorting algorithms. The prototype for std::sort looks something
I have a form which is posted to an external API. There is a
I'm working on get my site validated in an attempt to iron out issues
Here's my test case. If the form is posted, a 500 error response is
I have a bunch of functions (methods of a class actually) and I'm writing

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.