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 6236749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:54:03+00:00 2026-05-24T10:54:03+00:00

I’ve made an incredibly basic library, with a single function to check if the

  • 0

I’ve made an incredibly basic library, with a single function to check if the user is logged in now or not.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Lib {

    public function is_logged_in()
    {
        $CI =& get_instance();
        if($CI->session->userdata('uid') === FALSE)
        {
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
}

/* End of file Lib.php */

If I call the function from a controller, the code is definitely run and when not logged in it makes it into the if statement. I can add an echo to test that the code is definitely executed, but never is anything returned. If I change the return to a number, nothing is returned. If I change the return to a string, then and only then is stuff actually returned. I’m calling the function like $this->lib->is_logged_in(), and have added the library to the autoload.php file.

The return is definitely executed as the function is exited. error reporting is set to E_ALL. Why in the heck won’t this work?

(also yes I do realize the function isn’t complete and secure yet.)

  • 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-24T10:54:04+00:00Added an answer on May 24, 2026 at 10:54 am

    How are you determining that the return is executed? – NullUserException

    @NullUserException: The code block exits. I can echo prior to either return and it will run, I can echo after either and it will not. – Cyclone

    If you are trying to echo something after the return in your function, it will not work by design, I think this is probably universal to all languages. Anything after the return will not be executed. It will be parsed, but not executed.

    var_dump($this->lib->is_logged_in()) should give you bool(true) or bool(false), or a "Trying to get property of non-object" error if lib is not loaded correctly.

    Unless there is something you aren’t sharing with us, the function should work as expected.

    If you’re still in doubt, assign the return value to a variable, then var_dump() the variable before you return it. Should be the same result.

    EDIT: Sorry, I missed this in the long stream of comments:

    var_dump() reveals that false is indeed being returned, why can’t I simply echo it

    I don’t believe that echo’ing FALSE should give you any output, but echoing TRUE should give you 1.

    This also has nothing to do specifically with Codeigniter.

    For all practical purposes, there’s no good reason to echo the return value of this function, or really anything where you expect a boolean return value. If it is returning the value you expect, then it is working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.