Welcome Guest, Not a member yet? Register   Sign In
Avoiding nesting everything inside IF statements
#1

[eluser]BrianDHall[/eluser]
This just occurred to me. Here's something I find annoying that I want to avoid:

Code:
function control_panel()
{
if ($logged_in)
{
// all your code goes here
}
else
{
// they shouldn't be seing this page, so redirect or show login form
}
}

I hate this because it creates all that extra indenting and nesting when it seems so...inelegant. I had seen suggestions about using auth libraries to handle this or control it at a parent-class or constructor level, but this bit of code came to me:

Code:
function preview_listing()
    {
        
        if (!$logged in)
        {
            redirect('login_form');
            return;
        }

                // continue with your coding
        
    }

This should work shouldn't it? Am I missing something?

By "should work", it does infact appear to work, but I want to make sure I'm not breaking something silently that I won't notice until I want to slam my head into the wall.

I'd never seen it done this way before, and just wondered...well, why not?


Messages In This Thread
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 08:46 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:06 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:26 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:34 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 01:00 PM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 04:26 PM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 06:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB