Jump to content

What variables need to be declared first in a class?


cgm225

Recommended Posts

First let me say: Variables should always be declared at the beginning of the class

 

But, variables will be created on the fly if you are using them from within the the class. They will be PUBLIC. If you call a variable from outside the class (like $obj->varname) and varname has not been declared (either properly or on the fly) you will get an error.

Sometimes I see people declare all their variables, some people only a few.. My question is simply, what variables need to be declared first in a class?

 

This question is probably best answered by understanding the very basics of OOP.

 

Classes define the characteristics of objects.  They do this by providing (typically) a series of properties (variables) that define the attributes of the object, and methods (functions) that define the the behavior of the object.

 

The class properties depend on what you want the object to represent and do.  So, a database object won't have the same properties as a form validation object because they're two wildly different things, with different jobs, despite them both being objects.

 

It all boils down to what you want the objects to do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.