php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: code at henrik-gebauer dot de
New email:
PHP Version: OS:

 

 [2012-11-02 23:29 UTC] code at henrik-gebauer dot de
Description:
------------
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-02 23:39 UTC] rasmus@php.net
-Status: Open +Status: Duplicate
 [2012-11-02 23:39 UTC] rasmus@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 14:01:29 2025 UTC