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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:05:07+00:00 2026-05-31T00:05:07+00:00

I wrote a heredoc three weeks ago that was working great, and until today

  • 0

I wrote a heredoc three weeks ago that was working great, and until today it used five PHP variables.

Here is the heredoc:

   echo <<<itemDetails_HEREDOC
   <img src="$sitePath/images/logo-landing2.png" />
   <form action="$thisFilename" method="post" name="arti-form" id="arti-formId">
      <label style="display: inline-block; width: 140px">OWNER NAME:</label><input type="text" style="width: 300px"
           id="ownerId" name="ownerName" readonly="readonly" value="$theLoggedInUser" /><br />
      <label style="display: inline-block; width: 140px">THE ITEM:</label><input type="text"  style="width: 300px"
          readonly="readonly" id="itemNameId" name="itemName" value="$itemName" /><br />
      <label style="display: inline-block; width: 140px">LINK:</label><input type="text"  style="width: 300px"
          readonly="readonly" id="itemLinkId" name="link" value="$theLinkID" /><br />
      <label style="display: inline-block; width: 140px">ERA:</label><input type="text"  style="width: 70px"
          readonly="readonly" id="itemEraId" name="itemEra" value="$itemEra" /><br />
itemDetails_HEREDOC;

There are six (6) PHP variables in the above heredoc. The first one ($sitePath) does not work. I just added it today.

For some reason, the server is not replacing ‘$sitePath’ (the first PHP variable in my heredoc) correctly because when the browser receives the above page, an error is generated:

  Notice: Undefined variable: sitePath in C:\xampp\htdocs\Arti-facks\showItem.php on line 221

Here are the five PHP variables that have been in the heredoc and working fine for three weeks — they are being correctly replaced with their values before the HTML is sent to my browser:

  • $thisFilename
  • $theLoggedInUser
  • $itemName
  • $theLinkID
  • $itemEra

Just how do I know the above PHP variables are being correctly resolved on the server, with their associated values being put into the heredoc then sent to the browser?

Simple — I do a ‘view page source’ and instead of seeing ‘$thisFilename’, or ‘$itemName’, etc. in the HTML code sent by the server — I instead see their associated values in the above heredoc HTML content.

For example, the page source shows me that ‘$thisFilename‘ in the heredoc got correctly resolved to “showItem.php.”

My ‘$sitePath’ is declared in a global include file called “globals.php” and in that file, $sitePath is declared like this:

  $sitePath = "http://localhost/Arti-facks";

And at the top of showItem.php I have had, for the past three weeks, this include statement to pull in globals.php:

  require_once 'globals.php'; // Variables and statics used throughout

So today I added the $sitePath declaration (above) inside of globals.php

To prove that showItem.php is able to ‘see’ the newly-declared $sitePath I added to globals.php, I echo the variable — sure enough, showItem.php is 100% able to ‘see’ my newly-declared $sitePath.

And yet — despite that — and despite three weeks of using the above heredoc with its five other PHP variables —
the heredoc is not getting $sitePath.

When I ‘view page source’ here’s what I see for the $sitePath line of the heredoc above:

    <img src="/images/logo-landing2.png" />

You can see that the $sitePath part before the /images/logo-landing2.png is blank or missing.

Why have I, for three solid problem-free weeks, been getting five successfully-resolved PHP variables in the above heredoc, yet I add a 6th PHP variable today and it’s as if

“Goodness, your quota for PHP variables in your heredoc there was maxed out at 5. And now we see you’re trying to use a 6th PHP variable — what were you thinking.”

  • 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-31T00:05:08+00:00Added an answer on May 31, 2026 at 12:05 am

    Since the HEREDOC is called inside a function, the global variable $sitePath is not in scope. At the top of the function, use the global keyword:

    function yourfunction() {
      global $sitePath;
    
      // Then build the HEREDOC
    }
    

    Or use the $GLOBALS array inside the HEREDOC:

    echo <<<itemDetails_HEREDOC
       <img src="{$GLOBALS['sitePath']}/images/logo-landing2.png" />   
       <form action="$thisFilename" method="post" name="arti-form" id="arti-formId">
          ...snip...
    
    itemDetails_HEREDOC;
    

    Most prefereable: a function parameter

    Or preferable above either option, pass the $sitePath variable into functions that need it as a parameter.

    function yourfunction($sitePath) {
      // now $sitePath is in scope without 
      // reaching into the global namespace
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a console program in c# that takes up to three files as
I've used heredoc syntax in server-side php to clean up the code -- my
I wrote a windows service using VB that read some legacy data from Visual
I wrote myself a little downloading application so that I could easily grab a
I wrote a component that displays a filename, a thumbnail and has a button
I wrote a simple tool to generate a DBUnit XML dataset using queries that
I wrote an application that currently runs against a local instance of MySql. I
I wrote a makefile which behaves oddly. You can find it here: http://pastebit.com/pastie/8215 Basically
I wrote a program today and I need to show percentage in my output
Wrote a small app that accesses a bunch of search websites and puts the

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.