04-28-2008, 04:22 AM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
You use $this whenever you're calling a method or a variable of the class you happen to be inside of at the moment. Think of an object like a big ole cardboard box, that has a bunch of cool stuff inside of it. If you were on the outside of that box, and you wanted something from in it, you could say, $box->gimmeSomething(), but if you were on the inside of the box, you would say $this->gimmeSomething(). Stupid example, but see what I mean? It's an internal pointer, a reserved variable for calling all methods and variables within its own class.
As I've recently discovered, objects are fairly adept at handling dynamic variables, though for the purposes of your endeavour there's never any harm in initializing any vars you plan on using.
PHP Code:
class yourClass { var $var; // PHP 4 const CONST = ""; public $link; // just like methods, they'll accept public, protected, or private designations.
....
Also, you're copying an undefined variable $link to $this->link in your __construct. And I'm not sure the second should even work without being quoted, but eh. Maybe try something like,
PHP Code:
class DB_manager { const DB_SERVER = "localhost"; // your db server const DB_USER = "root"; // root? we should only use root from the cmd line! const DB_PASS = "rubberbabybuggybumpers"; const DB_NAME = "yourdatabase";
var $link; // resource identifier
public __construct { $this->dbConnect(DB_USER, DB_PASS, DB_NAME, DB_SERVER); echo "I'm sorry, Dave. I'm afraid I can't do that."; }
....
-m
|
|
|
|