php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48196 Bug in string concatenation after calling preg_match_all()
Submitted: 2009-05-08 20:33 UTC Modified: 2009-05-09 22:52 UTC
From: saulo_gil at argentina dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.*, 6CVS (2009-05-09) OS: win32 only - Windows XP
Private report: No CVE-ID: None
 [2009-05-08 20:33 UTC] saulo_gil at argentina dot com
Description:
------------
If I try to perform a simple concatenation involving a variable created from the matches output of preg_match_all() the resulting string is borked. Please see the code above.

What I want to do: echo "[" . $var . "]";


Reproduce code:
---------------
<?
function foo($s)
{
	preg_match_all("/PROCEDURE (.*)/i", $s, $matches);
	$name = (string) $matches[1][0];
	echo $name . "\n";
	return "[" . $name . "]";
}	


$s = "use providers
go

ALTER PROCEDURE SPD_EXECUTIVE_PROVIDER_DEALER
	(
		@EXECUTIVE_PROVIDER_ID	KEY_ID,
		@USER_SESSION_ID	ID
	)
/*
	Procedimiento 		: SPD_EXECUTIVE_PROVIDER_DEALER";
	
echo foo($s);
?>

Expected result:
----------------
[SPD_EXECUTIVE_PROVIDER_DEALER]

Actual result:
--------------
]SPD_EXECUTIVE_PROVIDER_DEALER

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-08 23:26 UTC] felipe@php.net
I can't reproduce it.
 [2009-05-09 01:18 UTC] saulo_gil at argentina dot com
Forgot to mention one thing, I've tried to reproduce this bug using the PHP CLI, calling this script with php.exe -q <script.php>
I've just reproduced it again on a freshly installed XP box. Same happened with PHP 5.2.9-2.
 [2009-05-09 04:03 UTC] jani@php.net
Verified under windows. Does NOT happen with other OSes.
 [2009-05-09 18:27 UTC] nlopess@php.net
The problem is that the input has \r. This means that $name also has a \r, which makes the console's cursor go back and override the '[' char. If you change the EOL of the input file just to \n, you'll see you expected output.

No bug here.
 [2009-05-09 22:52 UTC] saulo_gil at argentina dot com
Sorry for the false positive. Thank you very much.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 17:01:30 2024 UTC