#42790 [Opn->Bgs]: strrchr() doesn't work as expected with heredoc string containing blank line
| From: | tony2001@php.net | Date: | Tue, 02 Oct 2007 12:31:45 +0000 |
| Subject: | #42790 [Opn->Bgs]: strrchr() doesn't work as expected with heredoc string containing blank line | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-118093@lists.php.net to get a copy of this message | ||
ID: 42790
Updated by: tony2001@php.net
Reported By: mahesh dot vemula at in dot ibm dot com
-Status: Open
+Status: Bogus
Bug Type: Strings related
Operating System: RHEL 4, Windows XP
PHP Version: 5CVS-2007-09-28 (snap)
New Comment:
See this simple example:
<?php
$str1 = <<<EOD
EOD;
var_dump($str1);
?>
This code outputs 'string(0) ""', which explains why strrchr() or any
other function will not find any characters including newline in there.
The data in heredocs starts AFTER the initial new line and finished
BEFORE the ending newline, so it looks like this:
[START_DELIMITER and newline]data[newline and END_DELIMITER].
There is no data in your string, so strrchr() behaves correct.
Previous Comments:
------------------------------------------------------------------------
[2007-09-28 16:48:51] mahesh dot vemula at in dot ibm dot com
Description:
------------
strrchr() function can't find the new line when an heredoc string
containing only a blank line is given as input, whereas it works fine
when the heredoc string containing regular string with new line.
This is noticed on php5 and php6.
Reproduce code:
---------------
<?php
$str1 = <<<EOD
EOD;
$str2 = <<<EOD
hello
hiiiiiii
EOD;
//doesn't work as expected
var_dump( strrchr($str1, $str1) );
var_dump( strrchr($str1, "\n") );
var_dump( strrchr($str1, "
") );
//works as expected
var_dump( strrchr($str2, "\n") );
var_dump( strrchr($str2, "
") );
?>
Expected result:
----------------
string(1) "
"
string(1) "
"
string(1) "
"
string(9) "
hiiiiiii"
string(9) "
hiiiiiii"
Actual result:
--------------
bool(false)
bool(false)
bool(false)
string(9) "
hiiiiiii"
string(9) "
hiiiiiii"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42790&edit=1