Bramme Posted November 30, 2007 Share Posted November 30, 2007 Okay, this is not really a technical question, but more an issue of semantics (I think). I've been messing around with OO PHP for a few days now, starting a little home brewn application, extending Smarty. Now I've read OO PHP: Concepts, Techniques and Code, which helped me a lot, but I still have a question: Before you build any functions in your class, you declare your variables. Now, which variables should I declare? All of them I'll use in my Class, even though they're only used in one function, or should I rather only declare the one that will be used in multiple functions. I'm guessing it's the second one, but the book's not entirely clear on the item. Also, apparently, you can't declare a class variable using another variable? Quote Link to comment Share on other sites More sharing options...
jorgep Posted December 7, 2007 Share Posted December 7, 2007 For that specific issue, you have to see what is the purpose of the class you are creating. The class is an abstraction of the properties of an object in the real life, so the variables that you have to declare are the ones proprietaries of the object or the variables that you are going to represent that object. For example, an user have the properties: id, login, password, email, etc... all this properties (variables) should be declared if you are building a class for users. Of course if you have, let say, a temporal counter variable inside a for loop inside a function, it shouldn't (doesn't) have to be declared. Think about the scope of the variable, if the variable is just going to be used in one function and doesn't represent an important property of the object then it's not necessary, since you just need it for that function. Hope it helps, good luck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.