note 76444 added to language.operators.comparison

From: Date: Mon, 16 Jul 2007 10:49:54 +0000
Subject: note 76444 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-128611@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.197 Probable Submitter: 212.191.87.131 ---- Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php Edit -- https://master.php.net/note/edit/76444 Del: integrated -- https://master.php.net/note/delete/76444/integrated Del: useless -- https://master.php.net/note/delete/76444/useless Del: bad code -- https://master.php.net/note/delete/76444/bad+code Del: spam -- https://master.php.net/note/delete/76444/spam Del: non-english -- https://master.php.net/note/delete/76444/non-english Del: in docs -- https://master.php.net/note/delete/76444/in+docs Del: other reasons-- https://master.php.net/note/delete/76444 Reject -- https://master.php.net/note/reject/76444 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128611) next »