Passing variables from bash to php-cli

Hello everyone,

I've been looking how to pass variables between bash and php-cli in 1 file. So far i got this:

#!/bin/bash
echo "This is bash"

php << EOF
<?php
echo "This is php\n";
?>
EOF

I would now like to be able to pass a variable declared in the bash to the php. I already figured out i can split it in 2 files and get the variable in php with $argv, but i would really like my script to be 1 file.

Thanks in advance

---------- Post updated at 04:59 PM ---------- Previous update was at 04:35 PM ----------

Just managed to answer my own question. For those wondering:

bash: export VAR="value"
php: getenv("VAR");

---------- Post updated at 07:42 PM ---------- Previous update was at 05:59 PM ----------

ok next problem... i can't seem to declare any variables in the php.

#!/bin/bash
echo "This is bash"
export VAR="blabla"

/usr/bin/php -q << EOF
<?php

echo getenv("VAR");

?>
EOF

works good, while this doesn't work:

#!/bin/bash
echo "This is bash"
export VAR="blabla"

/usr/bin/php -q << EOF
<?php

$var = getenv("VAR");
echo $var;

?>
EOF

i get this error: PHP Parse error: syntax error, unexpected '=' in - on line 3