Bug #12674 Updated: string +' true', types misunderstanding (?)
| From: | joustin at plusnet dot pl | Date: | Thu, 09 Aug 2001 12:48:45 +0000 |
| Subject: | Bug #12674 Updated: string +' true', types misunderstanding (?) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-62716@lists.php.net to get a copy of this message | ||
ID: 12674
User updated by: joustin@plusnet.pl
Reported By: joustin@plusnet.pl
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Win2000 sp2
PHP Version: 4.0.6
New Comment:
I've come from perl, so it's quite easy for me to swallow that :) ... but others may
stuck.
I suggest dropping a line about this one in the manual.. a workaround is to use '===' as
the operator(PHP4) - of course as long as people would like to stuck to their current switch/if
schemes.
Previous Comments:
------------------------------------------------------------------------
[2001-08-09 08:46:19] joustin@plusnet.pl
Geez... THAT'll make some people quite confused/lost, when analysing the results from a
function with if/elseif or switch.
Consider:
<?
function foo(){
#...
return true;
#...or...
return 'works ok';
}
$foo = foo();
if(!$foo){
#whatever
}elseif($foo == 'works ok'){
#this will hit
}else{
#or else...
}
?>
------------------------------------------------------------------------
[2001-08-09 08:32:38] alindeman@php.net
any non-empty string will evaluate true!
------------------------------------------------------------------------
[2001-08-09 08:18:08] joustin@plusnet.pl
Hmm... why is that ?
Am I reading manual too briefly, or is there something with the operators ? might be bogus, but
please enlighten me:P
btw: I thought that there's no seperate boolean type =]
<?
function foo(){
return true;
}
if(foo() == 'whatever you like'){
echo '!?!? why is that equal ?';
}
?>
<?
function paranoid(){
return 1;
}
if(!(paranoid() == (string) 'whatever you like')){
echo 'hmm??';
}
?>
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12674&edit=1