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
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
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
Share on other sites

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.