Jump to content

PHP Proper Form.


clanstyles

Recommended Posts

This is a very broad question, so there really isn't a great answer for it. It really depends on what your doing.

 

Classes are for when you are repeating the same code over and over again with different values, you want to use these with large projects. You definitely don't need them for a login script.

Link to comment
Share on other sites

I almost never use classes for my data, I find that arrays suit my needs just fine 99% of the time.

 

I do use classes heavily for components of the site's back end.  For example, I have some of the following classes: CTemplate, CPage, CDatabase, etc.

 

One of the nicest features of using classes is they eliminate polluting the global namespace with variables and functions.

 

It's really difficult to learn how and why to use classes until you've worked on a large project or tried to reuse pieces of an old one.

Link to comment
Share on other sites

Whats the best way to learn?

By asking specific questions and practicing.

 

Right now i just use things like mysql_fetch_array for every peice of data I needed every time.

That's almost specific.  Pasting the code and asking if there's a more efficient way of doing the same thing would be even more specific.

 

 

Link to comment
Share on other sites

Why use classes when you can do like login  check right therre isset($_post['submit'] ect.. Why hold data that way?

 

Classes allow you to hide and re-use allot of functionality behind the scenes amongst other things. This does not necessarily mean its the proper way to go every time. Really, its up to the individual and the project at hand.

Link to comment
Share on other sites

but in classes, lets say i sset a var name = john. That var name is ALWAYS john while the session is around?

 

Not necessarily. Seriously... you need to do some reading. This is a huge topic your asking about and no one person is going to be able to explain it in a forum reply. This here might be a good place to start.

Link to comment
Share on other sites

I want to know wht the proper way to create a site is. Why use classes when you can do like login  check right therre isset($_post['submit'] ect.. Why hold data that way? Whats the proper way anyway?

 

Thank You

ya classes are not that important for you can have asite without a class but it make the script clean dynamic and short. for professional clean and short codes is the issue for professionals its not the question of can you do that? because they can but the question is that how can you do that? ;D

Link to comment
Share on other sites

I use classes in my scripts when I need to duplicate some functions I've written.

 

Classes to handle MySQL functions are in a MySQL class, HTML classes are in a HTML class and so on.

 

As I write more functions I added them to the relevant files and have so far built up a nice little library of handy functions. Saves me having to copy and paste code all the time.

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.