php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46588 Support for <? ?> within NOWDOC/HEREDOC syntax
Submitted: 2008-11-17 03:23 UTC Modified: 2008-11-18 06:05 UTC
From: vask at dmglobal dot net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.6 OS: Any
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: vask at dmglobal dot net
New email:
PHP Version: OS:

 

 [2008-11-17 03:23 UTC] vask at dmglobal dot net
Description:
------------
NOWDOC/HEREDOC only allows PHP values such as those allowed within a quoted string.  Permitting PHP code (such as functions) within NOWDOC/HEREDOC will allow more flexibility for coding. Also, when using a text editor, syntax styling for PHP and syntax styling for another language specified by the NOWDOC/HEREDOC within the same file would be more readable as breaking apart the NOWDOC/HEREDOC for a function call would no longer be necessary.

In the below examples I would like to reemphasize the importance of:
- PHP code with PHP syntax styling
- SQL code with SQL syntax styling

$sql = <<<SQL
  SELECT <?= get_it(); ?> LIMIT 1
SQL;

Instead of:
$sql = <<<SQL
  SELECT 
SQL;
$sql .= get_it();
$sql .= <<<SQL
  LIMIT 1
SQL;

Reproduce code:
---------------
$sql = <<<SQL
  SELECT <?= get_it(); ?> LIMIT 1
SQL;


Expected result:
----------------
$sql = <<<SQL
  SELECT <?= get_it(); ?> LIMIT 1
SQL;


Actual result:
--------------
Does NOT run.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-17 11:07 UTC] lbarnaud@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Adding this is very likely to break many existing codes.

Use this:
$it = get_it();
$sql = <<<SQL
  SELECT $it LIMIT 1
SQL;

Maybe you can also fake a property that will actually call a method (with an object using __get()):

$sql = <<<SQL
  SELECT $object->get_it LIMIT 1
SQL;
 [2008-11-18 06:05 UTC] vask at dmglobal dot net
Thanks for the reply and suggestions...

However, HEREDOC/NOWDOC or maybe even a WHATEVERDOC would be more FLEXIBLE and INTUITIVE if the entire part inside was essentially treated as a separate file. Thus allowing:

$sql = <<<SQL
  SELECT <?= get_it(); ?> LIMIT 1
SQL;

The reason I though this would be possible is because unlike quoted strings NOWDOC/HEREDOC doesn't require you to escape quotations.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 11:01:34 2024 UTC