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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
44 + 14 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 15:01:30 2024 UTC