Jump to content

New Instance of Class Rewriting Other Instance?


Resuwen

Recommended Posts

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.

 

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.