Hi nativerun,
In the database, in the USER table, user_id is AUTO_INCREMENT
When you insert a new user into the database
that new user gets assigned an ID. You can
retrieve that ID by doing a mysql_insert_id.
The author is doing that in this statement which
happens soon after the INSERT.
Code:
$this->uid = mysql_insert_id($GLOBALS['DB']);
This is the only place the user id gets set.
We don't want it set anywhere else.
The book shows us User.php in chapter 1.
It also shows us User.php in chapter 2 because
for chapter 2 they need to make a couple of changes
with regard to user permissions.
This relates to your concern about use of
$this->userId instead of $this->uid in the save function.
The book is not consistent.
In chapter 1, in the save function, when they update
the database the last line is
Code:
$this->isActive, $this->userId);
In chapter 2, same area, on page 36, and again on page 39,
they write it this way.
Code:
$this->isActive, $this->permission, $this->uid);
As to which one the authors want to use, I don't know.
I use $this->userId. Now, I have tried it with $this->uid
and it worked, but keep in mind I am still in the class User.
Throughout the rest of the book, when they are in
some different class, they use $user->userId. When the
__get method sees userId it will return the uid, so you
are still getting at the uid value in all cases.
He does talk about $uid and the magic methods briefly at
the top of page 9.
I hope this helps.
By the way, there are some other issues in this book that
you might want to take a look at for chapter 1.
They are discussed in this forum. A couple that I am involved
in are:
Chapter 1 - Login not checking for active status?
see errata. Wrox acknowledged this problem.
User registration forgotpass.php
see errata. Wrox acknowledged this problem.
(Ch.1 Conflicting Info) This should be the Greatest PHP & mySQL Book - EVER