php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32495 Echo not producing correct result.
Submitted: 2005-03-30 04:49 UTC Modified: 2005-03-30 14:26 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: mike at cocoweb dot co dot uk Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.0.3 OS: Windows XP
Private report: No CVE-ID: None
 [2005-03-30 04:49 UTC] mike at cocoweb dot co dot uk
Description:
------------
Unexpected output with echo statement.


Reproduce code:
---------------
<?php

// Expression 1
echo 'echo "<bob ".func()."></bob>";';

// Newline for "view source"
echo "\n";

// Expression 2
echo 'echo "<bob value=".func()."></bob>";';

// Newline for "view source"
echo "\n";

// Expression 3
echo 'echo "bob ".func()."></bob>";';

?>


Expected result:
----------------
echo "<bob ".func()."></bob>";

echo "<bob value=".func()."></bob>";

echo "bob ".func()."></bob>";


// Note extra newlines for ease of reading.

Actual result:
--------------
echo "<bob .func().></bob>";
echo "<bob value=".func()."></bob>";
echo "bob ".func()."></bob>";

Line 2 and 3 are expected.  Line 1 is just plain weird!

Note that the '=' after 'value' makes the output work correctly.  Bizarre.  I have looked in PHP books, the web and asked a couple of experts all to no avail.

You can reduce the original code down to:
echo 'echo "<bob =".func()."></bob>";';

and it will give expected result!  But remove the equals sign and the bug will occur.


Also note removing the first < (i.e. before bob) will work too.  (see expression 3).

I'm possibly having a REALLY bad coding day and making a REALLY simple error...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-30 07:45 UTC] sniper@php.net
I would be very worried if the output wasn't what you got.
(you're using single quotes..are you sure you've pasted the right code here? :)

 [2005-03-30 12:44 UTC] mike at cocoweb dot co dot uk
Check out "Actual result: Expression 1". The double quotes are missing around .func()

I should have made it more clear.
 [2005-03-30 12:52 UTC] tony2001@php.net
Works perfectly here.
 [2005-03-30 13:27 UTC] mike at cocoweb dot co dot uk
Are you sure you are getting:

   echo "<bob ".func()."></bob>"

and not, as I am getting:

   echo "<bob .func().></bob>"


I am definitely not making this up :o)  I have just reinstalled PHP 5.0.3 and it STILL fails.

I think we need to investigate this further before closing it.
 [2005-03-30 14:00 UTC] tony2001@php.net
Yes, I *AM* sure.
Try it with PHP CLI and if it works - fix your browser/editor instead.
 [2005-03-30 14:17 UTC] mike at cocoweb dot co dot uk
Thanks Tony.  I wasn't being awkard saying "are you sure?", it's just that I had double, nay triple checked my code, however your hint re browsers clinched it.

It fails on Mozilla Firefox and Netscape, but it works on Internet Explorer and Opera.  I had been unlucky as I only tested it on Firefox and Netscape, as I assumed it wasn't a browser problem, i.e. I've never had problems with PHP output and browsers before.

Thanks for everyone's help.  Very much appreciated.

** This problem is closed as it's a browser problem. **
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 12:01:29 2024 UTC