How can I avoid mistakes using the same variable name again?
https://softwareengineering.stackexchange.com/questions/183670
-
05-11-2019 - |
Question
This isn't a rare case and occurs with me often and I spent countless time trying to debug the code.
Latest example, this PHP code where I used $email
for the parameter and for object as well.
private function _mail( $email )
{
if( filter_var( $email, FILTER_VALIDATE_EMAIL ) ):
$email = new Zend_Mail();
$email->setSubject( $this->request->post('subject') )
->setBodyHtml( $this->request->post('message') )
->setFrom( $this->request->post('from') )
->addTo( $email )
->send();
unset($email);
endif;
}
It was throwing an error, strtr()
expects parameter 1 to be an string object given and it was really frustrating to browse through zend libraries to see what obscure string statement was throwing this error.
How to avoid such mistakes?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange