Using xdebug to find out why a variable is mysteriously set to 0
The key idea here is to use the "step into" functionality of PHPStorm to figure out when the second argument ($column within the function's declaration) gets changed.  $id_key shouldn't change at all if you're describing the calling conventions correctly, the second argument would have to be declared as &amp;$column, i.e., as a reference to the variable.  So I'm assuming that's what you mean. Otherwise, PHP passes a scalar variable "by value", and won't let any changes made to the variable in the body of the function change the original variable outside of it.

And there's nothing inside of the function that will change it either.  Here J. Reynolds is right; you're passing the wrong thing to fetchCol(), which wants an integer. But fetchCol() doesn't modify its argument either.

Since you're using xdebug, this then raises an important question: how are you using it?  Is your php process running on the same server as PHPStorm?

I ask this because one thing can definitely go wrong using xdebug: you can be debugging a different file than you think you are, if you're "mapping" a file on your server to a local file. If the file isn't the same, weird things can happen like what you describe. You may not really be on the line you think you are, since xdebug will tell PHPStorm the file line on the server, which may be a different line entirely on your local file. And the values of variables, if they display at all, may have different values than what the code displaying in PHPStorm allows.

Without knowing how you've set up PHPStorm to get to your PHP process, it's hard to know what exactly's going on. But you should describe what technique you're using, so folks can give you a better answer.