Tag issues

I have a discussion going on in the PHP Internals list regarding the future of tag setup that is showing some promise and I’d like to get some wider input and get it some momentum because I think I and the people I’ve been speaking with have hit upon something nice.

Basically a new php ini configuration would be added

php_tag_style

It would be a bit field. Bit 0 determines if the legacy tag behavior is implemented (0) or if no tags at all are implemented unless specified higher in the bitmask (1). So if you upgraded to php with this setting and set php_tag_style = 1 you would not have to use php tags in your php files – but you wouldn’t be able to use tags either. The higher bits correspond to tag styles

bit 1 – normal tags (<?php ?>)
bit 2 – short tags (<? ?>)
bit 3 – asp tags (<% %>)
bit 4 – short echo (<?php=, <?=, <%= )
bit 5 – script tags (<script type=“php”> </script> )

And if necessary more could be added. Tag style can be set in php.ini, in httpd.conf of htaccess, or at runtime. When the tag style is changed the setting affects all furture include and require statements - any that have already parsed will be unaffected.

Additionally, the include, require, include_once and require_once statements can take the same bitfield mask as a second argument to instruct them on how the file to be included will be parsed. Hence

include( ‘file.php’, 20 );

Would include a file using short tag parsing rules in addition to the standard file parsing rules. PHP_TAG constants would be added to make this more readable - allowing the statment to read as

include( ‘file.php’, PHP_TAGS_SHORT )

Still hammering this out in the discussion, but I think it adds a lot of flexibility as well as allowing for PHP libs to be written entirely tagless, which in an MVC framework is usually going to be 2/3rds of the framework.

I don’t know how the tags are in PHP6 but if you ask me, i would keep <? ?> only. I think the ones that are being removed? Heh. I mean if I use <%%> I know it is the ASP tags. So <??> is PHP.
What you written above it might make old code more compatible but still adds too much complexity.

I’m just curious…why would this be necessary?

Most PHP developers have defaulted to using the <?php ?> tags. I can see a benefit to the PHP echo tags <?= ?>, but the server doesn’t always have them enabled.

And you answered your own question. The reason short tags aren’t widespread is they cannot be reliably used. This proposal addresses this issue in a manner that is backwards compatible.

Second, in large frameworks there are often more files that have no html than there are with it. The ability to just turn tags off entirely for those scripts would be highly useful - and it removes an error point of whitespace getting inserted outside the tag. Not to mention that it brings allows PHP to cease being the only language out there that needs tags to delineate it’s source code at all times, which is a bit silly.