Drummin Posted August 24, 2012 Share Posted August 24, 2012 Looking at some code from post http://forums.phpfreaks.com/index.php?topic=364299.0 and was wondering if this is even php? Anyone seen this before with the equal sign after the question mark? <?=$aset[siteDescription]?>" Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/ Share on other sites More sharing options...
Christian F. Posted August 24, 2012 Share Posted August 24, 2012 Yes, this is called the "short tags notation". It's basically the same as <?php ecvho $aset[siteDescription]; ?>, though I suspect that 'SiteDescription' shouldn't be a constant. Anyway, the short tags have been deprecated for quite a while now, and the vast majority of web hosts have them turned off. So I recommend staying away from them, and just using the regular full tags instead. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372206 Share on other sites More sharing options...
Drummin Posted August 24, 2012 Author Share Posted August 24, 2012 Thanks. Just seemed odd <?= Would this be valid? <?php=$aset['SiteDescription']?> Personally I've always echoed anything that need to be rendered to the page. Just want to understand it, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372209 Share on other sites More sharing options...
ManiacDan Posted August 24, 2012 Share Posted August 24, 2012 Christian is right, but note that the "constant" SiteDescription probably needs to be quoted. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372210 Share on other sites More sharing options...
Drummin Posted August 24, 2012 Author Share Posted August 24, 2012 Never been real good with terminology but an unquoted name in brackets [name] would be a constant, right? And I understand that the "name" in brackets should be quoted ['name']. I do that all the time. But what is that called? Also can I get an answer if the code posted above is valid? Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372214 Share on other sites More sharing options...
trq Posted August 24, 2012 Share Posted August 24, 2012 And I understand that the "name" in brackets should be quoted ['name']. I do that all the time. But what is that called? It's a string. Also can I get an answer if the post above is valid? No, it's not valid. You know you can always try these simple script to see if they work? Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372216 Share on other sites More sharing options...
Drummin Posted August 24, 2012 Author Share Posted August 24, 2012 OK, so in other words, valid markup would be full echo then, correct? <?php echo $aset['SiteDescription']; ?> OR <?php echo "{$aset['SiteDescription']}"; ?> ... and there no valid "notation" type formatting with the equal sign for this and all lines like this would need to be replaced, correct? Note: it's not my site or code so testing isn't all that easy. Just wanted to understand if there was in fact notation type scripting and if so, the correct way to write it. Thanks for the feedback. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372220 Share on other sites More sharing options...
Christian F. Posted August 25, 2012 Share Posted August 25, 2012 A valid syntax would be the full echo, yes. Markup is something reserved for HTML, and similar languages. PS: No need to use the second example, all it does is add complexity without adding any functionality. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372232 Share on other sites More sharing options...
ignace Posted August 25, 2012 Share Posted August 25, 2012 Anyway, the short tags have been deprecated for quite a while now, and the vast majority of web hosts have them turned off. So I recommend staying away from them, and just using the regular full tags instead. They are enabled by default in PHP 5.4+ I consider it good practice to use them in view/template files, bad in all other instances, makes it more readable. http://www.php.net/manual/en/ini.core.php#ini.short-open-tag This directive also affected the shorthand <?= before PHP 5.4.0, which is identical to <? echo. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0, <?= is always available. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372292 Share on other sites More sharing options...
trq Posted August 25, 2012 Share Posted August 25, 2012 Not only are they enabled by default in 5.4, but <?= is always available, regardless of the short tags setting. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372294 Share on other sites More sharing options...
Drummin Posted August 25, 2012 Author Share Posted August 25, 2012 Thank you everyone. Quote Link to comment https://forums.phpfreaks.com/topic/267540-is-this-php/#findComment-1372301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.