homepage Welcome to WebmasterWorld Guest from 50.17.27.205
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Backwards/Forwards compatible syntax
Will the following PHP coding work with previous and future versions of php
nick279




msg:3929380
 8:53 am on Jun 9, 2009 (gmt 0)

I'm using a lot of seeming 'shortcuts' with my PHP at the moment, and just wanted to know if they seem like long-term solutions (and if they are compatible with older versions) - I've had a look through the docs but have struggled to find anything concrete.

1. {$braces} for outputting vars

I use this all the time now, instead of ever concatenating a string

$string1 = "text here {$var} without need for ".$xyz." concatenating";

2. (triple arrow) <<<

Whenever I'm outputting a string with more than 40-50 chars I always use

$output = <<<HTML
<h1>Header 1</h1>
<p>Paragraph1 - {$var1} etc</p>
HTML;

My worry is that I'm coding using something similar to 'short tags' and in future/previous PHP versions these may not work. Any thoughts?

 

coopster




msg:3929509
 12:53 pm on Jun 9, 2009 (gmt 0)

I think you can feel pretty good about interpolation and concatenation remaining quite stable and unchanging moving to the future. There may be some additions as we have seen lately [php.net] but nothing removed.

As far as backwards-compatibility -- IMHO if you are not running a PHP5 system today you are really putting yourself in a compromising position. Support for PHP 4 has been discontinued since 2007-12-31.

penders




msg:3929654
 3:38 pm on Jun 9, 2009 (gmt 0)

1. {$braces} for outputting vars

I use this all the time now, instead of ever concatenating a string

Just to clarify... it's not strictly the curly braces that allow you to output vars directly in a string, it's the fact you've enclosed the string in double quotes, or used heredoc (<<<) syntax. However, the curly braces are sometimes required in order to avoid ambiguity (PHP Manual: variable parsing [uk2.php.net]). In the examples you've given, the curly braces are optional.

The curly braces (complex syntax) and heredoc syntax were introduced in PHP 4 - so yes, it's backwards compatible. But, as coopster suggests, that shouldn't be an issue for new scripts.

nick279




msg:3929699
 4:45 pm on Jun 9, 2009 (gmt 0)

Many thanks Coopster/Penders - seems after reading both the comments/links in the post, it's cleared it up for me.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved