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 Build a Simple PHP Application Getting Started with PHP A Simple PHP Example

Is it neccesary to start with <?php or is it possible to start with <? only?

<? echo "question"; ?> or <?php echo "question"; ?> Don't they both work perfectly?

2 Answers

Mathieu HAYS
Mathieu HAYS
9,623 Points

Using <? would work but you might encounter issues on some server.

It's a better practice to use <?php

Andrew Shook
Andrew Shook
31,709 Points

To add to what Mathieu said, short tags (<? ?>) are not enabled by default on some servers. So, if you plan to share your code, using them might be a problem since some hosting plans will not allow you to turn them on. That means you might have to go back and change all your short tags into long tags. That's why its considered best practice to use the long tags, because they will always work.

short tags ()? If that is a short tag, what is a long tag then? Or do i have to follow courses and find out myself? It raises another question b.t.w.

I am used to use a command with () tags. Like:

 <?php echo ("Hello"); ?>

instead of :

 <?php echo "Hello"; ?>
Andrew Shook
Andrew Shook
31,709 Points

Sorry, I put:

(<? ?>)

But because I didn't put it in a code block the editor just put "()". So, just to make sure everything is clear:

<?php
    //these are long tags
?>

<?
    // these are short tags
?>

Now for your second question, "echo" is not a true function so you can use it with or without parentheses. There is no right or wrong way with that. Why you can do it either way I have no idea.

Thank you for your comments :)