Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

What does the ! mean?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

What does the ! mean?

Postby pugs421 » Tue Jul 01, 2003 12:55 pm

What does that mean when there is an exclaimation point in front of a varible? ex. !$HTTP_POST_FILES
pugs421
New php-forum User
New php-forum User
 
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby Joan Garnet » Tue Jul 01, 2003 4:20 pm

Returns true when is false.
Can't explain.... :?

http://es2.php.net/manual/en/language.o ... ogical.php
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby bezmond » Tue Jul 01, 2003 11:48 pm

similar to saying "if isn't" - so for example: if (!isset($variable)) {
as you probably know, if (isset()) means if it is set... if (!isset()) means if it is NOT set.

if ($1 == foo) {...

if ($1 !== foo) {...

!== means NOT equal to. :)

Hope this helps,
Andrew
User avatar
bezmond
Moderator
Moderator
 
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK

Postby swirlee » Sat Jul 05, 2003 2:25 pm

Actually, bezmond, your usage (assuming it wasn't just a typo. twice.) is wrong. Have a look at the docs.

!== doesn't mean "not equal". It means "not identical" and is the logical negation of the === ("identical") operator. != is the operator that means "not equal". In other words:

($a != $b) is logically equivalent to !($a == $b)
($a !== $b) is logically equivalent to !($a === $b)

I suppose it's an easy mistake to make, but I sure hope you haven't been using !== in place of != all this time. Though it probably hasn't caused your scripts many problems, people reading through your code have probably snickered a bit under their breath.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby bezmond » Sun Jul 06, 2003 1:35 am

!== will complete the same as != - because if it's not identical, then it's not equal :wink: ... but yes, it was a typo when I was tired :oops:

andrew
User avatar
bezmond
Moderator
Moderator
 
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK

Postby swirlee » Sun Jul 06, 2003 11:03 am

Well, I'm glad it was just a typo. I hate to see good programmers do bad things. But just for the sake of argument (though I know it's generally a bad idea to argue with a mod), and for those newbies who might be following along, your analysis isn't quite right. That is, there's a big difference in PHP between what is equal and what is identical. Observe:

Code: Select all
<?
$a = false;
$b = 0;
$c = '0';
$d = '';
// note that $e has not been set

echo $a == $b ? 'True' : 'False', "<br>\n";
echo $b == $c ? 'True' : 'False', "<br>\n";
echo $b == $d ? 'True' : 'False', "<br>\n";
echo $c == $d ? 'True' : 'False', "<br>\n";
echo $d == $e ? 'True' : 'False', "<br>\n";
/* Each of these EXCEPT the fourth one print 'True'
   Note that even though $b is equal to $c and $b  is equal to $d,
   $c does NOT equal $d. So much for the transitive theory. */

echo "<br>\n";

echo $a === $b ? 'True' : 'False', "<br>\n";
echo $b === $c ? 'True' : 'False', "<br>\n";
echo $b === $d ? 'True' : 'False', "<br>\n";
echo $c === $d ? 'True' : 'False', "<br>\n";
echo $d === $e ? 'True' : 'False', "<br>\n";
/* This is identical to the above, except the 'Identical'
   operator is used in place of the 'Equals' operator.
   Each of these will print "False" */

echo "<br>\n";

$f = true;
$g = 'abcdefghijklmnopqrstuvwxyz';
$h = array('One','Two','Three');

echo $f == $g ? 'True' : 'False', "<br>\n";
echo $f == $h ? 'True' : 'False', "<br>\n";
// Both of these will print "True"

echo "<br>\n";

echo $f === $g ? 'True' : 'False', "<br>\n";
echo $f === $h ? 'True' : 'False', "<br>\n";
// Both of these will print "False";
?>

I hope you've enjoyed this little demonstration.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby swirlee » Mon Jul 07, 2003 7:06 am

Hey, I just found a page that demonstrates exactly this:

http://www.php.net/manual/en/types.comparisons.php
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Re: What does the ! mean?

Postby WiZARD » Tue Jul 08, 2003 5:37 am

sign !.......
history of this sign begins from 1979 when UNIX born..... it's shell
value of ! mean NOT or opposite in scripts
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby swirlee » Tue Jul 08, 2003 7:22 am

If you really want to get technical, the exclamation point, fondly know to programmers as bang, pling, or shriek, was first used to denote logical NOT at least as early as 1969 in the B programming language, which (you guessed it) was the predecessor of C and was developed between 1969 and 1973. B is the earliest usage I've found, but I wouldn't be surprised (and would love to know) if someone can find an earlier reference. I think the bang is, perhaps, my favorite programming construct ever. Well, except for the object model.

References:
Users' Reference to B (7 January 1972)
The Development of the C Language (1993?)
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to PHP coding => General

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.