Jump to content

class help


ngreenwood6

Recommended Posts

ok so I have defined 5 constants in my config.php file, one of which is a global:

 

config.php

//get the global user
global $user;

//define the user id
define("USER_ID", $user->uid);

//define the database settings
define("DB_HOST", "host");
define("DB_DB", "db");
define("DB_USER", "user");
define("DB_PASS", "pass");

 

Now I create a class for my database and am trying to use those constants. All of them is working but the USER_ID. I dont know if it has something to do with it being a global but it is really annoying me. Here is how I am calling them in my db class

 

class db {	
//database connection
private $host = DB_HOST;
private $db = DB_DB;
private $user = DB_USER;
private $pass = DB_PASS;
        private $user_id = USER_ID;
}

 

Any ideas on why this is happening. Any help is appreciated.

Link to comment
Share on other sites

is $user->uid calling a function or a variable... if its a variable check its public? otherwise if its a function check its returning the correct result...

 

i'm assuming the "user" object is created before you define the constant (USER_ID)..?

 

 

Link to comment
Share on other sites

But its not working when I set $user_id = USER_ID; in the db class.

 

What code have you got that proves that? eg: How do you use $user_id within your class?

 

Also, this here....

 

define("USER_ID", $user->uid);

 

Suggests that $user is an object. Is it?

Link to comment
Share on other sites

Yes I believe that $user is an object, not sure because I dont know where it is located

 

So, when I asked you earlier where $user was defined and you replied "The $user is defined in a separate file. $user is a public variable." you really meant you have no idea where it is defined?

Link to comment
Share on other sites

but I know it is a variable, it is in a separate file, and it has to be public since I can access it lol.

 

But its not a simple variable, according to how your using it its an object. Can you use var_dump on it just prior to where you try to assign one of its properties to an object?

 

var_dump($user);

 

You might also try finding where it is defined. Surely your IDE has a search function? Try searching for $user =.

 

Any half decently written code wouldn't have an object like this floating around in the global scope.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.