Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:23:48+00:00 2026-05-25T18:23:48+00:00

I am currently using a class to control access to certain files in my

  • 0

I am currently using a class to control access to certain files in my site. The class works fine. However, i’ve recently been informed that I need to create a much more fine-grained system for one particular section of the site. My first inclination was to use nested if-else-if to set a couple of variables.

$admin = new Admin();

if( $admin->user_access('can_view_g2')) {
    $groupNum = $group2;
    $adminGroup = true;
    } else {

if( $admin->user_access('can_view_g3')) {
    $groupNum = $group3;
    $adminGroup = false;
    } else {

if( $admin->user_access('can_view_g4')) {
    $groupNum = $group4;
    $adminGroup = true;
    } else {

. . . 

Now I would like to eliminate a few lines of code and create a cleaner flow-control statement. I’d like to use a switch statement to handle this, but i’m not sure it is possible since I am accessing the methods and properties of a class.

switch ($admin->user_access($permission)) {

    case 'can_view_g2':
        $groupNum = $group2;
        $adminGroup = true;

    break;

    case 'can_view_g3':
        $groupNum = $group3;
        $adminGroup = true;;

    break;

    case 'can_view_g4':
        $groupNum = $group4;
        $adminGroup = true;

    . . .

What I have above is not working. Does anyone know of a way to do this or at least a more efficient flow control method to use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:23:49+00:00Added an answer on May 25, 2026 at 6:23 pm

    If your just trying to turn the block of if/else into a switch/case:

    switch (true) {
        case $admin->user_access('can_view_g2'):
            $groupNum = $group2;
            $adminGroup = true;
        break;
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using System.Windows.Forms webbrowser control to automate a webpage. Everything works fine to
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
I'm reading some XML with PHP and currently using the DOMDocument class to do
I am currently using NUnit and testing a class library. Up until now, I
I'm currently trying to authenticate via Active Directory Services using the PrincipalContext class. I
I currently have a class file with the following enumeration: using System; namespace Helper
I am using the URLUTF8Encoder.java class from W3C ( www.w3.org/International/URLUTF8Encoder.java ). Currently, it will
I am developing a web form using Visual Web Developer Currently I have class
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
I've got a Windows Forms control that I'm wrapping with a WindowsFormsHost -derived class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.