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

The Archive Base Latest Questions

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

1 <?php 2 class ACL 3 { 4 var $perms = array(); //Array :

  • 0
 1   <?php  
 2   class ACL  
 3   {  
 4       var $perms = array();        //Array : Stores the permissions for the user  
 5       var $userID = 0;            //Integer : Stores the ID of the current user  
 6       var $userRoles = array();    //Array : Stores the roles of the current user  
 7 
 8       function __constructor($userID = '')  
 9       {  
 10           if ($userID != '')  
 11          {  
 12               $this->userID = floatval($userID);  
 13           } else {  
 14               $this->userID = floatval($_SESSION['userID']);  
 15          }  
 16           $this->userRoles = $this->getUserRoles('ids');  
 17           $this->buildACL();  
 18       }  

This is part of a tutorial I’m learning creating a login system. I don’t know if I was at this for too long and my brain is fried but I’m getting confused about the boolean statement used as an argument in the function __constructor. See line 8.

This is the explanation given by the tutorial:

The __constructor() function is used to initialize the object when we
want to load an ACL. It is called automatically when we call new
ACL();. It is then passed a single, optional argument of the user to
load the ACL for. Inside the constructor, we check to see if a user ID
was passed in. If no ID was passed, we assume that we will load the
ACL for the currently logged in user; so we read in the session
variable for that. Alternatively, if we pass in a user ID, it allows
us to read and edit the ACL for a user other than the one logged in
(useful for your admin page).

Question #1… so this method is starting up as soon as you make a new class, and it is taking the boolean as an argument. I’m not understanding why you need to state the fact that userID = ‘ ‘. Couldn’t you just make it simpler and write: function __constructor($userID) { if ($userID != ”) ……..etc. etc. ?? Or do they mean the same thing?
The idea of stating a boolean never made sense to me, especially when you’re not using it in an IF statement to test it’s validity.

EDIT: I made a very weird slip. Sorry disregard the whole boolean thing, it’s not even a boolean statement. My error… 12 hours of learning programming is taking its toll.

Question 2: Is the variable $userID in line 5 the same as $userID in line8? I’m thinking no but I’m not sure. I’m sure that $userID on line 5 is the same as $this->userID on line 12 and line 15 but what about on line 8 and 10? I am confused. If the variable $userID on line 8 is NOT blank, then you are assigning $userID found on line 5 to the floatval of $userID on line 8??
I have a feeling that these are 2 different $userIDs. Why couldn’t this guy just use a different word if that’s the case? LOL

NOTE: I’ve been learning PHP for less than a week so these will seem like basic conceptual questions more than anything. Syntax isn’t really a problem for me, it’s the concepts.

Any help appreciated. Cheers.

  • 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-30T10:03:44+00:00Added an answer on May 30, 2026 at 10:03 am

    Okay,

    1. The method is not used every time you “make a new class”, it’s called every time an object is instantiated, meaning every time the new ClassName() statement is called. The reason function __construct($userID = '') is used and not function __construct($userID), is because we want to give it a default value. Meaning a user can either call new APC() or new APC("userID").
    2. No. The one declared on line 5 is an object property, it’s a variable that exists within each object (meaning if you instantiate 2 APC classes, you would have one variable for each object created, 2 in total).
      The one on line 8 is a function argument. When the method is called with an argument (new APC("userID")) that argument will be stored in that variable inside of the function.
      It’s coincidental that both of them have the same name.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP class that stores a complex multidimensional array, and rather than
class_1.php class class_1 { public function __construct() { require_once $_SERVER['DOCUMENT_ROOT'].'/array.php'; } } class_2.php class
Is there any way to call a php class (eg. $var = new className)
Example class code: <?php class example { public function forExample() { return true; }
Consider the following PHP class code class SuperIdea{ . . . static function getById($id){
My PHP class looks like that. <?php class htmlize { protected $base_dir; public function
I'm having a problem with a line of code like: $user->has('roles', ORM::factory('role', array('name' =>
i have one php class class veh extends dbClass { function smo($id) { $query=select
I have a large PHP class that has a large variable/function declaration and I
I have this PHP class class myclass{ function name($val){ echo this is name method

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.