|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63423 short open tag should be distinguished from other processing instructions
Submitted: 2012-11-02 23:29 UTC Modified: 2012-11-02 23:39 UTC
From: code at henrik-gebauer dot de Assigned:
Status: Duplicate Package: *Compile Issues
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: code at henrik-gebauer dot de
New email:
PHP Version: OS:


 [2012-11-02 23:29 UTC] code at henrik-gebauer dot de
The short open tag is very useful for readable templates: <?=$var?>, <? foreach ($array as $v): ?>, <? foreachend; ?> etc.

But on the other hand it interferes with other processing instructions like
<?xml version="1.0" encoding="utf-8"?> or <?xml-stylesheet href="style.css" type="text/css" media="all" ?>

So you have to use
<?="<?"?>xml version="1.0" encoding="utf-8"?>
or something similar in your template which makes it less readable.

The compiler should distinguish between a short PHP tag and other processing instructions. If the compiler is not sure if "<? something" is PHP code or not it should report an error as before.

Test script:
<?xml version="1.0" encoding="utf-8"?>
<?="hello world\n";?>
<?php echo "hello world\n"; ?>

Expected result:
<?xml version="1.0" encoding="utf-8"?>
hello world
hello world

Actual result:
Parse error: syntax error, unexpected 'version' (T_STRING) in ... on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-02 23:39 UTC]
-Status: Open +Status: Duplicate
 [2012-11-02 23:39 UTC]
This is already implemented in PHP 5.4. <?= is always enabled so you can turn 
short_tags off and you get the behaviour you are asking for.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 16:03:37 2021 UTC