Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When it is necessary to use Classes in PHP

I am a wordpress plugin developer. I saw the source of many pluginsand many plugin use "classes" in them and some without classes.

Many huge coded plugins like "wp-postratings" does not use Classes and some small plugins use Classes.

edit: Since classes have private, public and protected access specifiers, i feel a taste of security Does it increase security?

Other than PHP does other languages require classes ?

Is it compulsory to use Classes ?

I need some suggestions.

like image 357
Aakash Chakravarthy Avatar asked Jun 16 '10 14:06

Aakash Chakravarthy


3 Answers

No, it's not compulsory, nor does it increase security per-se. it's just a different style of programming.

Most programmers would agree that object-oriented programming (classes) has many advantages over modular programming (functions). But that's more of a religious debate that I'd rather not get into :)

like image 78
Eric Petroelje Avatar answered Oct 09 '22 19:10

Eric Petroelje


You should read about Object Oriented Programming. It is not compulsory to use classes but it can make code organization and maintenance of your code easier.

like image 44
Felix Kling Avatar answered Oct 09 '22 19:10

Felix Kling


It's obviously not a technical requirement, but if the code structure of your plugin can be described in 2 or more classes, I'd say go OO. It doesn't have anything to do with security but it might make your code cleaner and easier to maintain.

like image 2
Rob Avatar answered Oct 09 '22 20:10

Rob