php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12674 string +' true', types misunderstanding (?)
Submitted: 2001-08-09 08:18 UTC Modified: 2001-08-09 08:48 UTC
From: joustin at plusnet dot pl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.6 OS: Win2000 sp2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: joustin at plusnet dot pl
New email:
PHP Version: OS:

 

 [2001-08-09 08:18 UTC] joustin at plusnet dot 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??';
}
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-09 08:32 UTC] alindeman@php.net
any non-empty string will evaluate true!
 [2001-08-09 08:46 UTC] joustin at plusnet dot 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:48 UTC] joustin at plusnet dot pl
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 09:01:28 2025 UTC