difference <?php echo '$test'; ?> and <?=$test?>
Get the solution ↓↓↓Solution:
Assuming you really meant<?php echo $test; ?>
, the two are effectively the same thing. The question is, how portable do you want to be.<?php ?>
is supported just about anywhere that PHP is supported, however lots of admins disable<?= ?>
syntax.
Answer
Solution:
The former outputs the literal string$test
and the latter outputs the value$test
.
Answer
Solution:
<?= $test ?>
is identical to<?php echo $test; ?>
Since PHP 5.4.0 this<?= ... ?>
tag is always available regardless of php.ini settings on short tags, and short_open_tag directive only controls<? ... ?>
tag.
Also, relevant answer.
It is generally advised not to use short tags, but it is handy to use them only for simple outputs in templates with longer version only used for more complicated logic. That makes PHP code which tends to be messy more readable.
Answer
Solution:
I tend to use the<?= ?>
, which is calledshort_open_tags
, for templates or the "view" portion of my scripts. But this does have to explicitly be enabled in the php.ini so if you are working on a script for distribution it is best to avoid using it, unless you do not care if the buyers / users of the script may not haveshort_open_tags
turned on.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 8.0.2".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.