note 76444 deleted from language.operators.comparison by danbrown

From: Date: Thu, 18 Jun 2009 14:04:32 +0000
Subject: note 76444 deleted from language.operators.comparison by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157065@lists.php.net to get a copy of this message
Note Submitter: kocurro at kocurro dot pl ---- Today I notices problem with comparision different data types. My code is like that: function checkAndChange( $values) { $core = &Core::_(); $user = &$core->getUser(); switch( $user->changePassword( $values['oldpass'], $values['newpass'], $values['newpass2'])) { case( 'old'): return 'Bad current password'; case( 'user'): return 'Bad user'; case( 'new'): return 'Can\'t change'; default: return true; } return true; } function checkAndChange is called by callback, function changePassword returned string (indicating any error) or bool true (if no error). The problem was that if changePassword returned true it was always taking the first case - so in the example case( 'old'), if I changed order of cases giving case( 'new') as the first one then it was taken. This code was used to track the value of $res (which was the return from changePassword function checkAndChange( $values) { $core = &Core::_(); $user = &$core->getUser(); $res = $user->changePassword( $values['oldpass'], $values['newpass'], $values['newpass2']); echo( '<pre>'); print_r( $res); switch( $res) { case( 'old'): return 'Bad current password'; case( 'user'): return 'Bad user'; case( 'new'): return 'Can\'t change'; default: return true; } return true; } Even if constructions matched wrongly and even using $res === 'new'. Maybe that was a bug or something. How I dealed with this ? I stoped mixing the types and from that time changePassword is returning an empty string for success. Maybe this would help someone having the same problem as I had. PHP 4.4.7, Windows XP

« previous php.notes (#157065) next »