php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42958 [PATCH] Heredoc string constant folding
Submitted: 2007-10-13 22:00 UTC Modified: 2012-04-10 23:11 UTC
From: gopalv@php.net Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2007-10-13 (CVS) OS:
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:
17 - 7 = ?
Subscribe to this entry?

 
 [2007-10-13 22:00 UTC] gopalv@php.net
Description:
------------
Heredocs in php generates too many opcodes.

The tokenizer seems to be hooked directly into the zend_do_add_string()  call which creates a new opcode irrespective of previous opcode, where it could do better to just check whether data can be piggy-backed onto the previous opcode. 

Reproduce code:
---------------
<?php 
echo <<<EOF
foo bar is right
EOF;
?>

php52 -dvld.active heredoc.php


Expected result:
----------------
filename:       /tmp/heredoc.php
function name:  (null)
number of ops:  5
line     #  op                           fetch          ext  operands
-------------------------------------------------------------------------------
   4     0  INIT_STRING                                      ~0
         1  ADD_STRING                                       ~0, ~0, 'heredocs+are+fubar'
   5     2  ECHO                                                 ~0
   7     3  RETURN                                               1
         4  ZEND_HANDLE_EXCEPTION        


Actual result:
--------------
filename:       /tmp/heredoc.php
function name:  (null)
number of ops:  10
line     #  op                           fetch          ext  operands
-------------------------------------------------------------------------------
   4     0  INIT_STRING                                      ~0
         1  ADD_STRING                                       ~0, ~0, 'heredocs'
         2  ADD_STRING                                       ~0, ~0, '+'
         3  ADD_STRING                                       ~0, ~0, 'are'
         4  ADD_STRING                                       ~0, ~0, '+'
         5  ADD_STRING                                       ~0, ~0, 'fubar'
   5     6  ADD_STRING                                       ~0, ~0, ''
         7  ECHO                                                 ~0
   7     8  RETURN                                               1
         9  ZEND_HANDLE_EXCEPTION                                


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-13 22:04 UTC] gopalv@php.net
Find the patch/diff at

http://t3.dotgnu.info/code/zend_add_string.patch
 [2011-04-08 21:14 UTC] jani@php.net
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: Scripting Engine problem
 [2011-04-08 21:14 UTC] jani@php.net
Has this patch been applied yet..?
 [2011-04-11 08:58 UTC] gopalv@php.net
New location for the same patch

http://notmysock.org/code/zend_add_string_ver2.patch
 [2012-04-10 23:11 UTC] nikic@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: nikic
 [2012-04-10 23:11 UTC] nikic@php.net
Closing as this has already long been fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC