(!is_numeric($session->userID)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris93
Forum Newbie
Posts: 10
Joined: Fri Aug 01, 2014 4:43 pm

(!is_numeric($session->userID)

Post by chris93 »

Code: Select all

<?php

  /**
  * FR_User
  *
  * @author Joe Stump <joe@joestump.net>
  * @copyright Joe Stump <joe@joestump.net>
  * @license http://www.opensource.org/licenses/gpl-license.php
  * @package Framework
  * @filesource
  */

  /**
  * FR_User
  *
  * Base user object.
  *
  * @author Joe Stump <joe@joestump.net>
  * @package Framework
  */
  class FR_User extends FR_Object_DB
  {
      public $userID;
      public $email;
      public $password;
      public $fname;
      public $lname;
      public $posted;

      public function __construct($userID=null)
      {
          parent::__construct();

          if ($userID === null) {
              $session = FR_Session::singleton(); 
              if (!is_numeric($session->userID)) {
                  $userID = 0; 
              } else {
                  $userID = $session->userID;
              }
          }

          $sql = "SELECT *
                  FROM fr_users
                  WHERE userID=".$userID." AND 
                        status='active'";

          $result = $this->db->getRow($sql);
          if (!PEAR::isError($result) && is_array($result)) {
              $this->setFrom($result);
          }
      }

      public function __destruct()
      {
          parent::__destruct();
      }
  }

?>
-----------------------------

hi there can someone explain this line of code ;

(!is_numeric($session->userID) , idont understand the arrow sign

does it check if the session is not numeric or if the userID is not numeric ?

so it assumes that the user is not logged in and assigns userID = 0?


Notice that the constructor looks around for user IDs in various forms. If it receives a user ID, the class fetches the given user ID. If it does not receive a user ID, it checks the session; if a user ID is not present, it assumes the user is not logged in and it loads the special anonymous user record.

The special anonymous user allows me to have a special user for people not logged in. It allows me to easily and quickly check whether a user is logged in:


(!is_numeric($session->userID)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: (!is_numeric($session->userID)

Post by Celauran »

chris93 wrote:hi there can someone explain this line of code ;

(!is_numeric($session->userID) , idont understand the arrow sign

does it check if the session is not numeric or if the userID is not numeric ?
userID is a property of the $session object which, from the line above, is an instance of the FR_Session class. The -> operator is used to reference an object's properties and methods.
Post Reply