Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:19:01+00:00 2026-05-23T14:19:01+00:00

I started making a website, and quickly i found out that my code is

  • 0

I started making a website, and quickly i found out that my code is a mess. It’s been a while since I’ve been programming in PHP, and since then I learned OOP. Now while making an application in C# or java is pretty easy from this point of view, PHP is giving me trouble.

I used to program everything (in php) just from one line to another, with minimum amount of methods and no classes at all. So how much should be in methods, and where should this classes be?

Example:
I have account.php, and i want to update user information. So after checking that someone has sent some data if(isset($_POST[.. what next? I used to just make
all the checks like $email=CheckForRisksOrSomething($_POST["email]); and then just update mysql.

This brings me to the question, should I create a class User and what methods should it contain? Also WHERE should this class be saved, assuming that user.php would show you user’s profile.

Back to how much should be in classes, should i just use in a file like:

$smth = new Someclass();
if($smth->checkIfSaved()){
    $user = new User();
    $user->updateUser(/* all the $_POST stuff here? */); 
} else {
    $smth->showUserDetailsForm();
}

Also where should Someclass be saved?

So if ayone would give me an example of how to structure the following functionalities (in files, classes and possibly methods).

  • users (registration, login, editing account..)
  • picture with comments of it
  • news (also with comments)
  • administration

This is just an example of course, but i don’t want to keep on with my mess and then look at it three days later and just facepalm and wonder what did i write there. Well, i already did that today, that’s why I’m asking.


EDIT 24.2.2016

While this is an old question, as suggested look into a framework. While it might take a bit to set it up it increases development speed, code is nice and clean and a lot safer. I personally use Laravel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:19:02+00:00Added an answer on May 23, 2026 at 2:19 pm

    There’s more than one way to skin this cat, but I’ll recommend some helpful links and books for you.

    Zend’s Coding Standards: If you’re looking at how to structure, name, etc. your files, then I would look at how Zend suggests to do these things. By following their guidelines, you can create a package that is compatible with somebody else’s code using these same methods, as well.

    What you will want to do is create a folder specifically for your classes. How do you know when you’ll need to make a new class, and what to include? Good question!

    If you find yourself running into groups of information that is related, needs to be handled together a lot, or solves a particular problem, chances are you should create a new class that can handle it.

    For example, a User class to handle any sort of changes you want to make to a user of your site. Another example is a Role class that can perform tasks (or not) depending on if they’re an admin or not. The wonderful thing about Objects and Classes is you can create a User::$role (variable named $role in the User class) that is a Role class. So for instance, you will have a Role object in your User object. From here, your user object can now call to the role object by doing something like:

    class User {
        private $username;
        private $role;
    
        function __construct($username){
            $this->username = $username;
        }
        public function setRole($roleType){
            switch($roleType){
                case "admin":
                    $this->role = new Admin(); // contained in another class file
                    break;
                case "staff":
                    $this->role = new Staff(); // contained in another class file
                    break;
                default:
                    $this->role = new Visitor(); // contained in another class file
                } // end case
            } // end setRole
    } // end Class User
    
    $loggedInUser = new User("Bubba");
    $loggedInUser->setRole("admin");
    $loggedInUser->role->deleteMessage();
    

    In general, you will want to keep your code structured and separate, so that each class only handles information that it should have, and not do anything more than it should. If you find a class doing too many things, this means you found a good time to create another class to handle this new responsibility. How you tie it all together is generally a problem answered with “design patterns”. There is a very good book that covers both programming using objects and classes, as well as using design patterns.

    Check out the book “PHP 5 Objects, Patterns, and Practice” by Matt Zandstra, and published by Apress. It’s a wonderful book that dips your toes into OOP with PHP!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been making small scale projects for a while now. I haven't started a
I just started making this .php file and i cant seem to figure out
Awhile ago, I started making a program in vb.net. Since then i've lost the
I've been making my first ASP.NET Visual Studio website and I have just started
I started off programming in Basic on the ZX81 , then BASICA , GW-BASIC
I am programming my first real PHP website and am wondering how to make
I started making a 3d game. then I stopped for a some time and
I'm in the business of making website and applications that are not mission critical
I wrote a website a while ago that is a little messy in how
I started making a game, I have a global class that reads in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.