Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Issues
Author Message
testy1
Involved
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Thu Feb 19, 2009 11:55 pm Reply with quote

Version: 2.3.01

File: links.editadmins.php

Issue:
Code:


if (1==$radminsuper) {   adminmenu($admin_file . '.php?op=mod_authors', _EDITADMINS, 'authors.gif');
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Fri Feb 20, 2009 12:01 am Reply with quote

Could you explain the error you are reporting

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
testy1







PostPosted: Fri Feb 20, 2009 12:17 am Reply with quote

sorry forgot to write a descriptuion Sad

just wondering if this was back to front or not.....

Code:


1==$radminsuper
 
evaders99







PostPosted: Fri Feb 20, 2009 12:25 am Reply with quote

Readability, it makes more sense the other. But logically it is correct
You can do equality comparisons from variable-number and number-variable. It doesn't change the actual result
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Fri Feb 20, 2009 2:07 am Reply with quote

Oh it's much more important than readability. It is the preferred/only way to keep from making the common mistake of a variable assignment when you actually meant to do a variable comparison Smile. Note that the same is true when using the === operator.

$radminsuper = 1 which assigns $radminsuper the value of 1 when what you really meant was to a comparison $radminsuper == 1 Wink

Example: You want to compare the value of variable $radminsuper to see if it equals 1.

Typed correctly it should read (note the double == sign used for comparison)
if ($radminsuper == 1) /* rest of code */

However, if you mistakenly type (note the single = sign used for assignment in PHP but used for comparison in most any other language) the IF clause will always be TRUE and PHP will let you happily/blissfully carry on and can leave you scratching your head (or whatever killing me ) trying to figure out what's going on when no errors are thrown but the results are wrong! Note that PHP v5.? will throw a Warning that you may be using the wrong operator but it's still the best way to be all versions protected from your own devices!
if ($radminsuper = 1) /* rest of code */

So to avoid the potential and common error of assignment instead of comparison you reverse it
if (1==$radminsuper) /* rest of code */

That way, even if you make the same mistake it will not accept it and PHP will throw an ERROR.
if (1=$radminsuper) /* rest of code */
 
View user's profile Send private message
testy1







PostPosted: Fri Feb 20, 2009 3:08 am Reply with quote

mmmm I see, you have spiked my interest and just cost me the next day or so mucking around Sad

ROTFL
 
Raven







PostPosted: Fri Feb 20, 2009 3:21 am Reply with quote

speedtype Just trying to keep you interested Wink
 
evaders99







PostPosted: Fri Feb 20, 2009 6:53 pm Reply with quote

That is an interesting thought Raven. It is a good trick.
 
eldorado
Involved
Involved



Joined: Sep 10, 2008
Posts: 424
Location: France,Translator

PostPosted: Fri Feb 20, 2009 7:28 pm Reply with quote

yep... will save me some time now Very Happy
 
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Issues

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©