Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Standards and Best Practices Databases and International Concerns Understanding UTF-8

Matthew Stroh
Matthew Stroh
3,307 Points

I noticed you used <?= ?> instead of echo. I recall reading somewhere that it's not wide to use <?= instead of echo.

Is <?= acceptable for use, or is this a case of it being usable in only recent versions of PHP?

1 Answer

Codin - Codesmite
Codin - Codesmite
8,600 Points

There is a misunderstanding that using the short syntax for echo is bad practice. Using the short syntax for PHP tags

<?

on their own is very bad practice because it shares the same syntax as XML parsing

<?xml

It is reccomend to disable short_open_tag in PHP for this reason. Although

<?=

does not share the same syntax with xml.

In PHP 5.4+ the short syntax for echo has been seperated from short_open_tag so you can disable short_open_tag and the short syntax for echo will still function.

So in short if you are using PHP version 5.4+ it is not bad practice to use the short syntax. But if your application or website requires the use of an older version of PHP it is bad practice to use the short hand for echo.