Jump to content

PHP 5 OOP


shane18

Recommended Posts

I can write classes, and create objects from the classes... but I don't understand the use of them... what makes a list of classes better then a list of functions....

 

Example...

<? include("functions.php") ?>
validate("Shane","Username");

 

That would make sure Shane follows the regex made to check usernames...

 

That gets the job done, what makes a object better than that?

Link to comment
https://forums.phpfreaks.com/topic/192759-php-5-oop/
Share on other sites

this is just my understanding of it, so take it for what its worth:

 

php classes are a good way to organize data, and to a certain extent, make it more secure. you can create functions inside classes that cannot be called outside of that class, or ONLY on your __construct function, etc. Same goes with variables.

 

Also, when you're dealing with things like User ID's, its plain easier to use a class. For example, with functions you would have to pass every var you needed through the function name (ex: username($id_of_logged_in_user, $session_data)) for EVERY function.

 

whereas, in a class, you could just make it a public var, and use $this->id_of_logged_in_user and $this->session_data automatically without having to needlessly enter them into every function

 

I hope that made sense

Link to comment
https://forums.phpfreaks.com/topic/192759-php-5-oop/#findComment-1015461
Share on other sites

OOP has nothing to do with security. If you don't know the advantages of OOP you shouldn't be using it. It's not an easy concept so don't beat yourself up if you don't understand it right away.

 

In your limited example there would be no benefit in using OOP.

 

If you haven't already you can check this link out to get some general information about OOP.

Link to comment
https://forums.phpfreaks.com/topic/192759-php-5-oop/#findComment-1015463
Share on other sites

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.