1

I've tried a few different ways and per Is it possible to use php functions inside heredoc? it seems like the first one (for the GET) should work?

But it doesn't. Any way to do this simply, or should I just manually include the debug section?

  function bottom_module() {
    $print_r = print_r;

    $html = <<<"OUTPUT"
      <footer>
        ...
      </footer>

      <aside id="debug">
        <hr>
        <h3>Debug Area</h3>
        <pre>
          GET Contains:
          {$print_r($_GET)}
          POST Contains:
          $print_r($_POST)
          SESSION Contains:
          print_r($_SESSION)
        </pre>
      </aside>

    </body>
  </html>
  OUTPUT;
    echo $html;
  }
1
  • Unrelated to the problem you're currently having, but $print_r = print_r; refers to a constant called print_r. What you almost certainly intended to write was $print_r = 'print_r'; - that is, set $print_r to be a string with the content 'print_r'. In old versions of PHP, an odd feature guessed that undefined constants were intended to be strings, but it always issued a Notice or Warning while doing so, and the feature was removed in PHP 8.0 so it is an error instead. Commented Aug 13, 2022 at 15:46

1 Answer 1

4

What you will probably find is that the print_r() is displaying the value rather than including it in the output.

You should try using the second parameter which if set to true will return the value as a string instead...

   <pre>
      GET Contains:
      {$print_r($_GET, true)}

EDIT from OP for clarity: this solves the issue but as another reply said, $print_r must be declared as $print_r = 'print_r';

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.