php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6174 problem with sprintf, urlencode and string concatenation
Submitted: 2000-08-15 12:31 UTC Modified: 2000-10-12 09:34 UTC
From: johnw at cogs dot susx dot ac dot uk Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.1pl2 OS: Solaris 7
Private report: No CVE-ID: None
 [2000-08-15 12:31 UTC] johnw at cogs dot susx dot ac dot uk
The following script:

 <?
 
 function add_query_string($url, $qs) {
   return "$url?$qs";
 }
 
 function url_stem() { 
   return add_query_string("test.php", "arg1=foo");
 }
 
 function test() {
   for ($i=0; $i < 10; $i++) {
     $url=url_stem() 
             . sprintf("&arg2=%s",   urlencode("baz"));
     print("$i - $url<BR>\n");
   }
 }
 
 test();
 ?>

fails on ALTERNATE times round the loop, i.e.
it produces the output:

 0 - test.php?arg1=foo&arg2=baz
 1 -
 2 - test.php?arg1=foo&arg2=baz
 3 -
 4 - test.php?arg1=foo&arg2=baz
 5 -
 6 - test.php?arg1=foo&arg2=baz
 7 -
 8 - test.php?arg1=foo&arg2=baz
 9 -

I've boiled this down as much as I can (which is why the
code might look a bit silly).

PHP is statically linked into Apache 1.3.4 running
on a Sun Ultra 1.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-15 12:38 UTC] stas@php.net
Failed to reproduce that with latest CVS. Did you try it (available from snaps.php.net?)
 [2000-08-15 12:38 UTC] joey@php.net
Works for me in latest CVS on Solaris 2.6.
Can you try a snapshot (or wait for 4.0.2)?
 [2000-09-03 07:45 UTC] waldschrott@php.net
Works for me too.
Closed due to missing user feedback.

 [2000-09-04 07:27 UTC] johnw at cogs dot susx dot ac dot uk
I've downloaded and installed PHP 4.0.2
This bug still occurs
You can see it happening by going to the URL
 http://cogslib.cogs.susx.ac.uk/bug.php
Please do not class this as fixed - it isn't!
 [2000-09-17 17:15 UTC] stas@php.net
Was able to reproduce it on Solaris. Will investigate further.
 [2000-09-17 17:40 UTC] johnw at cogs dot susx dot ac dot uk
Thanks for looking further Stas.
I just tried 
 lynx -dump http://cogslib.cogs.susx.ac.uk/bug.php
and the output was slightly different, though still
incorrect, i.e.
   0 - 8??&arg2=baz
   1 - test.php?arg1=foo&arg2=baz
   2 - 5,h &arg2=baz
   3 - test.php?arg1=foo&arg2=baz
   4 - #X &arg2=baz
   5 - test.php?arg1=foo&arg2=baz
   6 - 9?8 &arg2=baz
   7 - test.php?arg1=foo&arg2=baz
   8 - 8?? &arg2=baz
   9 - test.php?arg1=foo&arg2=baz
hope that helps!


 [2000-09-20 01:35 UTC] stas@php.net
Should be fixed in CVS, please check.
 [2000-10-12 09:34 UTC] johnw at cogs dot susx dot ac dot uk
I've downloaded and installed PHP 4.0.3
The bug now seems fixed - thanks!
John Williams (johnw@cogs.susx.ac.uk)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 09:01:30 2024 UTC