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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:15:36+00:00 2026-05-22T02:15:36+00:00

is following somehow possible? And if so how?! I know i could pass a

  • 0

is following somehow possible? And if so how?!
I know i could pass a parameter but I’d like it to be dynamic!

<?php

class my_class {

  protected $parent = NULL;

  public function __construct() {

    // now i'd like to get the name of the function where this class has been called
    $this->parent = get_parent_function();

  }

  public function parent() {
    return $this->parent;
  }

}

function some_random_function() {
  // Do something
  $object = new my_class();

  print $object->parent(); // returns: some_random_function
}

?>

Thanks in advance!

  • 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-22T02:15:36+00:00Added an answer on May 22, 2026 at 2:15 am

    Frankly this seems like a pretty bad design choice, however it would be possible to do this using call stack introspection using the PHP builtin debug_backtrace function. The following example is from the php documentation for debug_backtrace:

    <?php
    // filename: /tmp/a.php
    
    function a_test($str)
    {
        echo "\nHi: $str";
        var_dump(debug_backtrace());
    }
    
    a_test('friend');
    ?>
    
    <?php
    // filename: /tmp/b.php
    include_once '/tmp/a.php';
    ?>
    

    If b.php is executed, the output could look like this:

    Hi: friend
    array(2) {
    [0]=>
    array(4) {
        ["file"] => string(10) "/tmp/a.php"
        ["line"] => int(10)
        ["function"] => string(6) "a_test"
        ["args"]=>
        array(1) {
          [0] => &string(6) "friend"
        }
    }
    [1]=>
    array(4) {
        ["file"] => string(10) "/tmp/b.php"
        ["line"] => int(2)
        ["args"] =>
        array(1) {
          [0] => string(10) "/tmp/a.php"
        }
        ["function"] => string(12) "include_once"
      }
    }
    

    If you were clever you could use the function name of the function in the backtrace to call it, e.g. debug_backtrace()[1]['function'](), but this will only work if the function is defined in the scope that you are currently executing in. See the php documentation on variable functions for more info on calling functions by their name from a string.

    In my opinion, though, there should be no reason for you to do this in a well designed program. Perhaps you should think about using objects and references to objects instead.

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

Sidebar

Related Questions

weird que i know, but could something like the following be achived somehow? int
Possible Duplicate: Django dynamic model fields Good Morning guys! Scenario is the following. For
Base class MessageHandler has derived classes. They would like to pass messages to each
The following modify method somehow modifies the whole @x array instead of just simply
Somehow it seems that when I use gotoSimple in the following setup, my data
Following is the association between 2 models: class FotoGossip < ActiveRecord::Base has_many :uploads end
Suppose I have an application with the following code: public class Node { public
I don't know if what I'm trying to accomplish is possible at all. I
I'm new to JQuery and I'd like to know if you've got any idea
Is it possible to load a premain-class from a jar library packed within a

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.