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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:09:40+00:00 2026-05-29T19:09:40+00:00

Can I do this, maybe using ReflectionClass ? myprintr($some_object); function myprintr(){ foreach(func_get_args() as $key

  • 0

Can I do this, maybe using ReflectionClass ?

myprintr($some_object);


function myprintr(){
  foreach(func_get_args() as $key => $arg){

    // here I want to get the name of the passed variable, "some_object"
    // $key seems to be numeric...
  }


}
  • 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-29T19:09:43+00:00Added an answer on May 29, 2026 at 7:09 pm

    If the user passes an object to myprintr(), then you can use

    if (is_object($arg)) {
        $className = get_class($arg);
    }
    

    to get the name of the object type that has been passed, which you can then feed to reflection

    but the reflection constructor will accept either a class name or an object as an argument, so you don’t even need the class name to instantiate a reflection class

    EDIT

    Just for the sake of playing a bit with this concept (and not creating any dependency on globals), or on whether the arguments are variables, values returned from functions, strings, etc:

    class Test{};
    
    function myTest() {
        $some_object = new Test();
        myprintr($some_object);
    }
    
    function myprintr(){
        $callStack = debug_backtrace();
        $calledAt = $callStack[0];
    
        $callingFile = file($calledAt['file'],FILE_IGNORE_NEW_LINES);
        $callingLine = $callingFile[$calledAt['line']-1];
        $callingLine = substr($callingLine,strpos($callingLine,__METHOD__));
        $calledWithArgNames = trim(substr($matches[0],1,-1));
    
        var_dump($calledWithArgNames);
    
        $args = func_get_args();
    
        foreach($args as $arg) {
            var_dump($arg);
        }
    }
    
    myTest();
    
    $some_object = new Test();
    $some_other_object = &$some_object;
    
    $t = 2;
    $gazebo = "summer house";
    $visigoth = pi() / 2; myprintr($some_other_object,pi(), atan2(pi(),$t), $visigoth, "Hello $t World", $gazebo); $t = log($t/$visigoth);
    

    This retrieves all the arguments passed by the calling function in $calledWithArgNames, so for the first call you have:

    '$some_object'
    

    and for the second call:

    '$some_other_object,pi(), atan2(pi(),$t), $visigoth, "Hello $t World", $gazebo'
    

    This still requires splitting down into the individual arguments (a preg_split on commas, except where they’re inside braces), but is certainly a step closer to what you’re actually asking for.

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

Sidebar

Related Questions

I want to rewrite this, maybe using predicates, or Lambda, how can I do
I know which using the GetForegroundWindow function i can get the current active window
Maybe this cannot be done, but please help or suggest how this can be
I know this maybe a basic question but I just can't seem to find
This maybe a stupid question, but as I can not easily undo my change
Can I use default arguments in a constructor like this maybe Soldier(int entyID, int
Maybe I am just falling asleep (or not!), but how can you do this:
There maybe some simlar questions to this but I can't see anything that really
This is baffling me, maybe somebody can shine the light of education on my
I've searched around but I can't find any information about this; maybe I'm not

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.