scottybwoy Posted September 13, 2006 Share Posted September 13, 2006 Another quicky for the day, what is this not doing in this function :if (! $this->authorise($user))does it mean that if the user is not autorised (depending on the function authorise) what happens if there is not yet a value for $user?Thanks Link to comment https://forums.phpfreaks.com/topic/20621-not-really-understanding-this-not/ Share on other sites More sharing options...
Daniel0 Posted September 13, 2006 Share Posted September 13, 2006 It checks if $this->authorise($user) not returns true (returns false). So if $this->authorise returns true if the user is authorized then it checks if the user is not authorized.What happens if $user is null, empty, false or something similar depends on what is inside the function.It's spelled authori[b]z[/b]ed by the way ;) Link to comment https://forums.phpfreaks.com/topic/20621-not-really-understanding-this-not/#findComment-91078 Share on other sites More sharing options...
jpadie Posted September 13, 2006 Share Posted September 13, 2006 if $user is not populated then essentially the function call will look like[code]if (!$this->authorised())[/code]you need to look at the authorised method to see what will happen if a value is not passed. if it is nicely written then it will return false. if the exception is not properly handled it may fail with an error. alternatively the class may be written so that it is impossible for the $user variable not to be populated with something.typically a function like this will return true or false but it can return anything. assuming true/false: yes (to your first question) the antecedent (!) on the method call will mean "take the following action if the user is not authorised". Link to comment https://forums.phpfreaks.com/topic/20621-not-really-understanding-this-not/#findComment-91083 Share on other sites More sharing options...
scottybwoy Posted September 13, 2006 Author Share Posted September 13, 2006 OK, here is my autorise function :[code]<?phpfunction authorise($user) { echo $user; if ($user = TRUE) { $stmnt = "SELECT USER_ID FROM users WHERE uNAME = $user"; $result = mssql_query($stmnt); if ($result != TRUE) { echo "You are not entered in the Database, please see the Administrator"; exit; } else { $success = TRUE; } } else { $success = FALSE; return $success; } }?>[/code]Is there a better way of writing it? What I want it to do is get the user to report to admin f they are not already in the database and if they are already in the database just go passed the original function to load the page. Thanks Link to comment https://forums.phpfreaks.com/topic/20621-not-really-understanding-this-not/#findComment-91092 Share on other sites More sharing options...
Daniel0 Posted September 13, 2006 Share Posted September 13, 2006 I would write it like this: [code]<?phpfunction authorise($user){ echo $user; if($user == TRUE) { if(!mssql_query("SELECT USER_ID FROM users WHERE uNAME = {$user}")) { echo "You are not entered in the Database, please see the Administrator"; exit; } else { $success = TRUE; } } else { $success = FALSE; } return $success;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/20621-not-really-understanding-this-not/#findComment-91098 Share on other sites More sharing options...
scottybwoy Posted September 13, 2006 Author Share Posted September 13, 2006 Cheers, never knew you could use ! on the query, was stupid of me to put my return directly under the FALSE statement, Thanks Daniel0 Link to comment https://forums.phpfreaks.com/topic/20621-not-really-understanding-this-not/#findComment-91103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.