RecoilUK wrote:Hi guys
I was wondering what and how everyone uses Classes when coding for PHP.
I know they are supposed to be used so you are not typing a lot of repetive code, and therefore your code or more organised, but what other purpose do they serve?
I had the following idea as a security measure ...
Hi, I just want to comment on this, since your interest in using classes somewhat interests me too.
Since you've already mentioned the use of classes, I would suggest that you also start with the dicipline of OOP. In this way, you'll be able to maximize your knowledge about classes. I would like to share some key points for using classes, and here are some of them.
First of all, since you mentioned it. Classes are not only used to keep you from writing cocdes over and over, you can easily do that in a funciton. Classes are meant to be used if you want a clean mplementation, and a well structured code for your application. Classes basically creates objects, and objects are meant not only to contain functions that you can reuse, but it is also meant to co-exist with one another, that each can have relationships, if you design them to be. An object is composed of members, properties, and methods.
It is good that you are thinking of security when creating an application. Inline to this I would also suggest that you also provide security for your code. As per object oriented programming is concerned, your class should contain members that are private, properties that are responsible for accessing the members, and methods that contains the functionalities that you need. The reason for this is so that the members cannot be accessed by any other function directly , but only through the properties. Now, this is also what I would consider as one major concern with php's OOP , due to the fact that each variable or function in a class is by default public.
So, I hope this opens up your mind, and get you more interested on the whole programming environment. Have fun.