Forum Moderators: coopster

Message Too Old, No Replies

PHP Shorthand

<? vs <?php

         

madmatt69

8:26 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone,

Kind of a silly question, but a friend of mine was saying that using <? instead of <?php was better because a) it reduces file size (obviously not much) and b) it speeds up render time.

Does it actually speed up the render time? I'm sure it's barely noticable, but every little bit helps, right?

Any other shorthand tips?

jatar_k

9:14 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that won't make a difference

other shorthand

var echo'ing in html

<?= $myvar?>

mcibor

9:32 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's better to use <?PHP, because that's the main opening string. <? is just a shortened version.

In speed there's no difference. What difference is in reading 3 bytes more, especially as you use new line breaks and many spaces.

Best regards
Michal Cibor

PS. I use both versions, whichever I write works :)

Birdman

9:37 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just for the record:

[us2.php.net...]

There are four sets of tags which can be used to denote blocks of PHP code. Of these, only two (<?php. . .?> and <script language="php">. . .</script>) are always available; the others can be turned on or off from the php.ini configuration file. While the short-form tags and ASP-style tags may be convenient, they are not as portable as the longer versions. Also, if you intend to embed PHP code in XML or XHTML, you will need to use the <?php. . .?> form to conform to the XML.

...The second way is not available always. Short tags are available only when they have been enabled. This can be done via the short_tags() function (PHP 3 only), by enabling the short_open_tag configuration setting in the PHP config file, or by compiling PHP with the --enable-short-tags option to configure. Even if it is enabled by default in php.ini-dist, use of short tags are discouraged.

Dang, I use short tags alot too.

PCInk

9:45 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I believe that some server versions of PHP will support <?, whilst all should support <?PHP. So for portability, use <?PHP

Note that although the file size will be smaller, what is sent to the end user (over the internet, the slowest chain in the link) is exactly the same because the <? and <?PHP are never sent. The output of the PHP programming is sent. So the space saving ONLY applies to your bandwidth when you upload the files and this will normally be minimal. As file sizes are in segments on a hard disk, a one byte file can occupy the same amount of disk space as a 200 byte file. So your server space usage in unlikely to be affected much at all.

ergophobe

12:45 am on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just a note RE Michal and PCInk's comments...

remember, as Birdman said,

"only two (<?php. . .?> and <script language="php">. . .</script>) are always available"

Note that php and many OSes are case-sensitive, so I would take the official word to mean that <?php is always available, but <?PHP really shouldn't be.

When I'm being good, I use <?php. I'm not often good. Fortunately, there's always grep.

Tom