|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21791 problems with reference passing through layers of functions in windows/IIS/sapi
Submitted: 2003-01-21 00:55 UTC Modified: 2003-02-09 03:06 UTC
From: fishrunsrap at hotmail dot com Assigned:
Status: Closed Package: MSSQL related
PHP Version: 4.3.0 OS: windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
42 - 39 = ?
Subscribe to this entry?

 [2003-01-21 00:55 UTC] fishrunsrap at hotmail dot com
I upgraded PHP to 4.3.0, from 4.2.3, running in IIS5 as a SAPI module. I had hacked stored procedure support for MSSQL into the PEAR DB class with a function like: 

function spBindOutputParam($stmt, $name, &$outref, $type) { 
return mssql_bind($stmt, $name, &$outref, $type, true, false); 

... right? then, in my own DBAbstraction classes, I had something like: 

function bindOutputParam($name, &$outref, $type) { 
/// debugger 
global $debug; 

//$debug->println("DBStoredProcedure::bindOutputParam() called, outref = ".$outref."", 5); 
return $this->db_connection->spBindOutputParam($this->db_stmt, $name, &$outref, $type); 

... and so on, up through the layers of abstraction in my application framework, always passing the output parameter $outref by value. I upgraded to PHP 4.3.0 and it BROKE. the functions all completely failed to modify $outref. it works fine, I stress, in PHP 4.2.3. I desperately tried a bunch of stuff like removing the '&' from ONLY the function signatures, or ONLY the subsequent calls, or what have you. totally busted. has anyone run into anything like this? I'm guessing it's a PHP 4.2.3->4.3.0 thing but who knows? maybe also with MSSQL in PHP. let me know. thanks! 



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-21 00:58 UTC]
Please provide a _SHORT_ and _COMPLETE_ example script
which can be used to reproduce this.

 [2003-01-21 14:52 UTC] fishrunsrap at hotmail dot com
the following test script:

function inner2(&$val) {
	$val = "Changed!";

function inner(&$val) {

function outer(&$val) {

$val = "The same.";

echo("val = ".$val."\n");

... actually executes as it should on both 4.2.3 and 4.3.0 in my environment. I therefore would like to reopen the bug as one in the MSSQL extension on windows.
 [2003-01-21 14:54 UTC] fishrunsrap at hotmail dot com
under PHP 4.3.0 in IIS5/sapi, the mssql_bind() function does not modify variables passed in for output parameters.
 [2003-01-22 22:04 UTC]
About this:

function spBindOutputParam($stmt, $name, &$outref, $type) { 
   return mssql_bind($stmt, $name, &$outref, $type, true, false); 

Have you tried adding 'error_reporting(E_ALL);' in the beginning of the script? You propably get some warnings?

Try changing the call to:

return mssql_bind($stmt,$name,$outref,$type, true,false); 

ie. don't pass $outref by reference, it's done internally..

 [2003-01-22 23:51 UTC] fishrunsrap at hotmail dot com
ok, I will try this tomorrow in the AM, but I have to ask: what has changed from 4.2.3 to 4.3.0 to make this type of implicit pass-by-reference thing happen? why does it work perfectly normally in 4.2.3? I could find nothing in the changelog that referred to this issue.
 [2003-01-23 18:16 UTC] fishrunsrap at hotmail dot com
changed spBindOutputParam to feed mssql_bind() the variable sans ampersand ('$outref', versus '&$outref', as it was) and no go. reference passing still busted. sorry.
 [2003-02-09 03:06 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

the 3rd argument to mssql_bind() is forced to be passed by ref.

This is not a problem with mssql_bind() but with a change to the way parameters are returned from stored procedures. In php 4.3.0 the support for multiple results in stored procedures was added. If you are using 4.3.0 you need to call mssql_next_result() at least once before getting the return and output values.

IN 4.3.1 (and current CVS) this has been fixed so as long as your SP is not returning any results you will get return and output values right after the call to mssql_exec(). If you are getting one or more results you need to call mssql_next_result() or use the new optional parameter to mssql_exec() to skip all results.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 18 01:05:45 2022 UTC