php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27278 sprintf(): global variable changing type when passed to function by value...
Submitted: 2004-02-16 09:35 UTC Modified: 2004-02-16 12:02 UTC
From: phpbug at billix dot franken dot de Assigned:
Status: Closed Package: Variables related
PHP Version: 4CVS, 5CVS (2004-02-16) OS: *
Private report: No CVE-ID:
 [2004-02-16 09:35 UTC] phpbug at billix dot franken dot de
Description:
------------
when I pass a variable of type string to a function (by
value not by reference!) and modify the local parameter,
the type of the global variable changes from string to int
although the local variable is still a string!

./configure --disable-cgi --enable-cli

No changes made to php-ini-dist

This worked as expected in PHP 4.3.5RC1 and earlier.

Reproduce code:
---------------
function foo ( $a )
{
  print "foo(a)="; var_dump($a);
  print "GLOBALS['x']="; var_dump($GLOBALS["x"]);
  $a=sprintf("%02d",$a);
  print "GLOBALS['x']="; var_dump($GLOBALS["x"]);
  print "foo(a)="; var_dump($a);
}

print "PHP-Version:".phpversion()."\n";
$x="02";
print "x="; var_dump($x);
foo($x);
print "x="; var_dump($x);


Expected result:
----------------
PHP-Version:4.3.5RC1
x=string(2) "02"
foo(a)=string(2) "02"
GLOBALS['x']=string(2) "02"
GLOBALS['x']=string(2) "02"
foo(a)=string(2) "02"
x=string(2) "02"


Actual result:
--------------
PHP-Version:4.3.5RC2
x=string(2) "02"
foo(a)=string(2) "02"
GLOBALS['x']=string(2) "02"
GLOBALS['x']=int(2)
foo(a)=string(2) "02"
x=int(2)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-16 11:47 UTC] sniper@php.net
Little bit simpler test script:

<?php

function foo ( $a )
{
  $a=sprintf("%02d",$a);
  var_dump($a);
}

$x="02";
var_dump($x);
foo($x);
var_dump($x);

?>

Expected result:
----------------
string(2) "02"
string(2) "02"
string(2) "02"

 [2004-02-16 12:02 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 16:02:23 2014 UTC