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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:30:58+00:00 2026-05-26T12:30:58+00:00

For PHP testing scripts I need a function report() that will report results of

  • 0

For PHP testing scripts I need a function report() that will report results of some expressions, like:

report(in_array(null, $array));
report(in_array(false, $array)); 
# etc...

The output should look like:

in_array(null, $array) => false
in_array(false, $array) => true

So I want to print the expression along with the result. Thus in the report function I need some means how to print the expression which was given by the caller:

function report($expr)
{
    SOME_FUNCTION($expr) 
        # function I'm looking for!!
        # function which would write the string 'in_array(null, $array)' to output!
    echo " => ";
    echo $expr;
    echo "<br>";
}

Is there any such function that would dump the expression as given by the caller?
I know this can’t be “normal” function, this would need to be somehow bound to PHP internals. But if there are magic things like debug_print_backtrace(), __FUNCTION__ or __LINE__, then I think there still can be some chance…

  • 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-26T12:30:58+00:00Added an answer on May 26, 2026 at 12:30 pm

    Directly, no there is no clean method to do what you want.

    With that said, you could use debug_backtrace to get the stack. Then, all you need to do is walk the stack back one (go to the 2nd array element), and you have the file and line information. Then, you’d need to parse that line to extract the function name and the inputs.

    It wouldn’t be clean. It wouldn’t likely be easy. And it wouldn’t be 100% reliable. But it should work for most cases…

    here’s a simple case of a utility function to do that. Just call it with the function name, and it’ll give you the literal caller of the function:

    function getArgs($func) {
        $d = debug_backtrace();
        $call = $d[1];
        $file = file($call['file']);
        $line = $file[$call['line'] - 1];
        if (preg_match('(' . preg_quote($func, '(') . '\((.*)\);)', $line, $match)) {
            return $match[1];
        }
        return $line;
    }
    

    And here’s an example:

    function doSomething($arg) {
        $call = getArgs(__FUNCTION__);
        echo $call . ' - ' . $arg;
    }
    
    doSomething(strlen('foo'));
    

    Would output:

    strlen(‘foo’) – 3

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

Sidebar

Related Questions

I am trying to make a function in PHP that will allow me to
<script type=text/javascript> function testing() { $.ajax({ type: POST, url: testing.php, data: call=+$(#abc).val(), success: function(msg){
this question is like this one , except it's for PHP testing via browser.
I have just started out with testing some php mvc framework In it, it
I have a php server that is running my domain name. For testing purposes
Currently I'm trying to install PHP 5.3.0 on some Linux testing server. As we've
I need to create a PHP script that receives XML input via an HTTP
I'm having some problems with the php script below that I'm currently working on.
I would like to redefine certain functions in PHP that are already built for
While testing some scripts, I've noticed, if expiration time is little (not zero) -

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.