Resuwen Posted August 18, 2014 Share Posted August 18, 2014 I've been looking everywhere for a solution of this but I can't find one... Basically what I did was created a class named USER. public class USER{ private static $USER = array(); public function __construct($U='') { // if $U is not entered (=='') then set $U to MY USER ID ($_COOKIE['user']) // do a mysql query by the ID (ala $U) and store the results to self::$USER } public function ID() { return self::$USER['id']; } } This is the code I am running... I do a user profile page that shows different properties of the USER from the database: USERNAME(),ID(),PHONE(),EMAIL(), etc. etc. // creates an instance of a different user (other than myself) $PROFILE = new USER($ID); // $ID: 26 will retrieve USERNAME: Test // create an instance of user class for myself using the cookie holding my id $ME = new USER($_COOKIE['user']) // $_COOKIE['user']: 01 will retrieve USERNAME: Monster echo($PROFILE->USERNAME()); // displays Monster echo($PROFILE->ID()); // displays 01 Any idea what I am doing wrong? I would assume that $PROFILE->USERNAME() would display Test and $ME->USERNAME() would show monster. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 18, 2014 Share Posted August 18, 2014 What you're doing wrong is making things static. Static values are the same for every single instance of the class. So don't do that. Quote Link to comment Share on other sites More sharing options...
Resuwen Posted August 18, 2014 Author Share Posted August 18, 2014 Thanks, that did the trick, you rock! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.