0

Very stupid question how to check 2 things in 1 if. , I'm getting errors typing code in a wrong way.

I need to check if expression A isset, OR expression B isset in 1 IF statement

My code is if (isset(expression1) OR isset(expression2)) {}

this is an yii framework this is fullcode

if (isset(Yii::app()->user->viewUsersPage) OR isset(Yii::app()->user->checkAccess('guest')))

something is wrong there...

13
  • 1
    Why are you isset ing an expression ?? Commented Mar 19, 2014 at 15:34
  • Actually your script is correct, though use || instead of OR Commented Mar 19, 2014 at 15:35
  • actuaaly it's not an expression but a call to some variable. sorry Commented Mar 19, 2014 at 15:35
  • @crypticous you can use OR just fine. Commented Mar 19, 2014 at 15:35
  • Could you show a part of your expressions ? Commented Mar 19, 2014 at 15:36

2 Answers 2

2

What's this? Checking isset on a function return?

isset(Yii::app()->user->checkAccess('guest'))

Maybe you want to check for true:

if (isset(Yii::app()->user->viewUsersPage) || Yii::app()->user->checkAccess('guest'))

Or:

if (isset(Yii::app()->user->viewUsersPage) || (Yii::app()->user->checkAccess('guest') == true))

I don't know the code, but maybe you should be checking for true on viewUsersPage as well?

Maybe also try this instead of isset(Yii::app()->user->viewUsersPage:

if (property_exists(Yii::app()->user, 'viewUsersPage') || Yii::app()->user->checkAccess('guest'))

Though isset should work fine.

Sign up to request clarification or add additional context in comments.

5 Comments

this code works, but the problem is that now I'm getting messages that WebUser.viewUsersPage is not defined. And I understand why it is. And that's why I was trying to bypass it with isset. I mean the WebUser.viewUsersPage maybe present and just check it, and may not present.
AbraCadaver second part of IF is OK. Problem is with first part, which sometimes exist in my application and sometimes no. And because of that I'm checking it here in the way to bypass it without errors if it is not present. That's why I write isset, but I still getting errors :(
Edited, try property_exists()
HEY sorry , was my fault! This code works just fine!
property_exists not needed. isset works fine, had some other errors, in line after this. Thanks for the help!
-1

We use the || operator. See here.

if (isset(Yii::app()->user->viewUsersPage) || isset(Yii::app()->user->checkAccess('guest'))) {

   // do something
}

2 Comments

Wow... the page you even link uses OR as well as || in the first example.
|| has a greater precedence than OR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.