Jump to content

Is using the same variable name within two different functions ok?


webref.eu

Recommended Posts

Hi All

 

I'm using the two functions given below on the same page of code.  You'll notice that they both contain the same variable, i.e. $result.  I think this is fine, as the scope of the variable will be limited to within the function.  Would you agree?  I just want to check I'm not going to cause myself any headaches. 

 

Thanks all. 

 

 

 

//CODE STARTS

 

function IsValidUsername($Username) {

  $result = TRUE;

 

  //ereg() searches a string for matches to the regular expression given in pattern in a case-sensitive way.

  //in regular expression, ^ means anything that is not

  if(ereg('[^A-Za-z0-9]', $Username)) {

    $result = FALSE;

  }

  return $result;

}

 

 

 

 

function IsValidPassword($Password) {

  $result = TRUE;

 

  //ereg() searches a string for matches to the regular expression given in pattern in a case-sensitive way.

  //in regular expression, ^ means anything that is not

  if(ereg('[^A-Za-z0-9]', $Password)) {

    $result = FALSE;

  }

  return $result;

}

 

//CODE ENDS

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.