I'm working on an old PHP website, and NetBeans is complaining about an uninitialized variable. I'm seeing some code like this:
$app->soapAPIVersion($apiVersion);
$_SESSION['apiVersion'] = $apiVersion;
The function looks something like this:
function soapAPIVersion(&$apiVersion)
{
$apiVersion = '';
$result = false;
$soapResult = $client->call('getAPIVersion', array('sessionKey' => $sessionKey), $url);
if (is_string($soapResult))
{
$apiVersion = $soapResult;
$result = true;
}
return $result;
}
I believe it's using this line to initialize the $apiVersion
variable:
$app->soapAPIVersion($apiVersion);
For better coding practice, should that really be this:
$apiVersion = '';
$app->soapAPIVersion($apiVersion);
Or is it a valid trick?
preg_match
). Yes, this is a bug in NetBeans, and there's no reason to initialize$apiVersion
before calling the function. You will only get a warning if you read its value before initializing it. – David Harkness Apr 14 at 6:54