Jump to content

[SOLVED] heredox syntax with NEWLY defined variables?? (quick logic question)


dsaba

Recommended Posts

i'm defining a variable with heredoc syntax like so:

$imageurl = "http://myimageurl.jpg";
$var = <<<VAR
<img src="$imageurl">
VAR;

 

later in my script I say:

$imageurl = "http://newimageurl.jpg";
echo $var;

 

will it echo <img src="http://newimageurl.jpg">
OR            <img src="http://myimageurl.jpg">

 

??

 

also what if i reference an undefined variable in my heredox syntax, and then later define it?

 

-thanks

It will echo <img src="http://myimageurl.jpg">, becuase you set $var to the original value of $imageurl,  and var did not get reset after you changed the value of $imageurl.  If you wanted it to change, you could do this:

 

$imageurl = "http://myimageurl.jpg";

$var = <<<VAR

<img src="$imageurl">

VAR;

$imageurl = "http://newimageurl.jpg";

echo $var;

$var = <<<VAR

<img src="$imageurl">

VAR;

echo $var;

 

That way it resets $var.

 

Help?

ya thats what i thought thanks

 

there is nothign special with variables inside of heredox syntax and it does not act like functions with variables

 

i will place the heredoc variable into a function so I can define it once, and change the variable as many times as I want, without having to re-define the heredoc variable

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.