I am new to PHP so sorry for naive question but every PHP file I've seen starts with <?php. Is that mandatory? Are there any well-known workarounds for not having it?
Coming from Node it looks a bit awkward to me.
Welcome to PHP Alex!
Yes it is mandatory one. Since PHP sometimes when embedded between HTML, the interpreter finds the code when enclosed within such tags. You can read more about it here
BTW, you can use short open tag <? (But discouraged since it is disabled by default and can be used only after modifying the php.ini configuration file.)
You can also use short echo tag <?= ?> when you want to print. This will be like template engine!
FYI, previously PHP had script tags but it has been removed since the release of PHP 7.0.0. It was like:
<script language="php">
...
</script>
And so is the ASP style tags too <% ... %>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With