Jump to content

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.

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.