![]() |
Constructing a proper class
When do you use '$this->'? Anyway, the following class works fine, I just feel like I wrote it like an idiot. Could someone tell me what I did not-so-well?
PHP Code:
|
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:
PHP Code:
|
| All times are GMT. The time now is 06:45 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0