php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28148 parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARI
Submitted: 2004-04-25 21:59 UTC Modified: 2004-04-26 08:41 UTC
From: ca50015 at yahoo dot com Assigned:
Status: Not a bug Package: Compile Failure
PHP Version: 5.0.0RC1 OS: windows 98 se
Private report: No CVE-ID: None
 [2004-04-25 21:59 UTC] ca50015 at yahoo dot com
Description:
------------
Got parse error when double-quoted string contains variable.

[Code]
$pattern = "/\<$tagName[^\>]*\>/i"; 
[/Code]

[Error message]
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in php5bug.php on line 6
[/Error message]

I'm using php5.0.0rc1 in windows 98 from command line
the command is: "php -f php5bug.php"

the same I got while test with php5.0.0RC2


Reproduce code:
---------------
<?php
$text = "<script></script>";
$tagName = 'script';

//These won't work	
$pattern = "/\<$tagName[^\>]*\>/i"; //backslash not escaped
$pattern = "/\\<$tagName[^\\>]*\\>/i"; // backslash escaped

//These work
$pattern = "/\<" . $tagName . "[^\>]*\>/i"; //backslash not escaped
$pattern = "/\\<" . $tagName . "[^\\>]*\\>/i"; // backslash escaped
?>

Expected result:
----------------
variables in double-quoted string could be altered


Actual result:
--------------

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\home\php5bug.php on line 6



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-25 22:12 UTC] pollita@php.net
It's seeing $tagname[^\\>]  as an array element (with an index of ^\> which is, of course, invalid in an encapsed string context.

Not sure if this falls into "buggy" or "expected" beahvior as it's a little gray...

 [2004-04-25 22:35 UTC] derick@php.net
This is indeed expected behavior, use "<{$tagname}[..." instead.
 [2004-04-26 00:49 UTC] ca50015 at yahoo dot com
Thanks for Pollita and Derick.

I ought to have noticed that.
 [2004-04-26 08:41 UTC] derick@php.net
It's still bogus...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 10:01:31 2024 UTC