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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 00:01:24 2020 UTC