EllisLab text mark
Advanced Search
     
CI 1.7: Will automatic short tags be deprecated?
Posted: 24 October 2008 07:18 AM
Avatar
Joined: 2008-04-09
12 posts

1.7 is a fantastic release that has fixed my 2 biggest annoyances. But I noticed a new style guide, which appears to drop hints that in the future we may see more “approved” 3rd party libraries. On the subject of short tags the style guide says the following:

Short Open Tags

Always use full PHP opening tags, in case a server does not have short_open_tag enabled.

INCORRECT:
<? echo $foo; ?>

<?=$foo?>

CORRECT:
<?php echo $foo; ?>

However, the alternative PHP syntax page still suggests support for automatic short tags in those cases where the server does not have short_open_tag enabled. This seems an inconsistent message.

My question is: will short tag support be deprecated in future versions? I personally like them, because they keep the code looking cleaner, but if they’re generally considered bad practice, I’ll welcome guidance on this.

 
Posted: 24 October 2008 07:31 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-22
402 posts

why bad practice?

I always like these short tags.

 Signature 

Blogmer - Open source blogging software based on codeigniter
Blogmer Documentation
Web Design company and FREE PHP MySQL Webhosting

 
Posted: 24 October 2008 07:47 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

Short tags are a php.ini setting an this can be switched off. CI has a build-in parser for short tags but this slows down the page rendering.

I think the idea behind that rule is to write code that works on every server. So if you still want to use short tags make sure you switch them on, on your server.

You have to read the style guide as a guide and not as documentation. I think the use of incorrect and correct should be replaced by don’t use and use. As you demonstrated the wording can confuse people.

 
Posted: 24 October 2008 12:05 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-07
2507 posts

My question is: will short tag support be deprecated in future versions?

More the other way around, actually.  The style guide is copied from EE’s developer guidelines.  EE doesn’t have the option to rewrite short tags, but it will (theoretically) when EE 2 comes out.
I follow a pretty basic rule here.  Long syntax for open source.  Short tags if I can control the environment.

 Signature 
 
Posted: 24 October 2008 05:07 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-23
3194 posts

I love reading threads when xwero and inparo have written.  Always bang on… thanks guys.

To be explicit, the guide is a guide which we tried to use to make people’s code similar, but short tags are certainly fine.  Short tag rewriting won’t be deprecated in the near future.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

 
Posted: 24 October 2008 05:20 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-22
402 posts

ok I got the point.. I’ll keep this in my mind for future while writing open sources..

 Signature 

Blogmer - Open source blogging software based on codeigniter
Blogmer Documentation
Web Design company and FREE PHP MySQL Webhosting

 
Posted: 25 October 2008 07:12 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2006-06-05
54 posts
xwero - 24 October 2008 11:47 AM

CI has a build-in parser for short tags but this slows down the page rendering.

Does this mean that a site coded using short tags will run slower than one coded with the full “echo” statements?
And if so, is there a large difference in speed?

 
Posted: 25 October 2008 08:27 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

Sarre it depends on the rewrite_short_tags setting. If it’s set to true all files will be checked for short tags. loader class snippet :

if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
        
{
            
echo eval('?>'.preg_replace("/;*\s*\?>/""; ?>"str_replace('<?=''<?php echo 'file_get_contents($_ci_path))));
        

I have no figures on the performance hit but if the setting is false the file just gets included.