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 Functions Introducing Functions PHP Function Arguments

Oly Su
Oly Su
6,119 Points

<?php ?> tag not closed in this course

Hi there,

Just noticed that the code shown in the video from this course in the PHP track does not close the <?php ?> tag.

Is this not necessary because the entire index.php file is in PHP and not HTML is present?

What happens when the PHP script is run, does it automatically close the PHP?

Many thanks :)

Felipe Alarcon
Felipe Alarcon
2,930 Points

if there is no html code along php code I read somewhere that it's actually recommended not to add the closing tag as it adds a whitespace which can potentially mess up your design, I was having a look at some MVC frameworks and as business logic and presentation are separeted there are many php files (if not all) that follow this "style".

2 Answers

Kevin Korte
Kevin Korte
28,148 Points

Yep, if the last thing in my file is a PHP block, I don't close it out. It eliminates the chance of getting an error because of white space at the end of the file.

Hi,

actually, omitting the closing tag is good solution for avoiding any blank characters at the on the file which could throw an error. Although, it's not necessary to close php tags. It's just a good practice.