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 8624823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:37:40+00:00 2026-06-12T07:37:40+00:00

All of the code in my project is procedural. It isn’t using any framework,

  • 0

All of the code in my project is procedural. It isn’t using any framework, or any MVC structure. Most of the PHP is form handlers with some logic. So lots of code like this:

<?php

require "headerFile.php";

$user = array(); // filled with user data

if (isset($_POST['submitButton'])) {
    if (isset($_POST['money'])) {
        if (is_numeric($_POST['money'])) { // I don't actually validate numbers this way
            if ($_POST['money'] <= $user['money']) {
                $query = mysql_query("SELECT * FROM someTable WHERE id={$user['id']}");

                if($result = mysql_fetch_array($query)) {
                    if ($someOtherCheck == $user['someOtherData']) {
                        /*
                         * run some queries, give user some item
                         *
                         */
                    } else {
                        echo "This isn't right.";
                    }
                } else {
                    echo "You don't have a row in some table!";
                }
            } else {
                echo "You don't have that much money!";
            }
        } else {
            echo "Enter a valid number";
        }
    } else {
        echo "Enter how much you want to wager.";
    }
}

// some hard coded form goes here

require "footerFile.php";

?>

There are over a hundred of these forms and nested if handlers, some that are similar with more/fewer conditions.

I want to start using OOP and I’ve been reading up on design patterns but I can’t seem to find anything that applicable to my project.

I’m adding loads of new blocks of code similar to the block above, I don’t want to copy and paste and just change a couple of bits here and there, what are my options?

  • 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-06-12T07:37:41+00:00Added an answer on June 12, 2026 at 7:37 am

    I want to start using OOP and I’ve been reading up on design patterns but I can’t seem to find anything that applicable to my project.

    You don’t have to start with patterns yet .. understand the basics and you can progress form there ..

    This is a basic example

    if (isset($_POST['submitButton'])) {
    
        $db = new \mysqli("localhost", "user", "pass", "db");
    
        $user = new User("Juddling Stack", 123456);
        $user->setMoney(500.01);
    
        $player = new PlayerRegister($db, $user);
    
        if (! isset($_POST['money']) || ! is_numeric($_POST['money']))
            $player->addError("Enter Valid Wager Money");
    
        if ($_POST['money'] <= $user['money']) {
            $player->addError("You don't have that much money!");
        }
    
        try {
            $player->doSQL();
        } catch ( BaseException $e ) {
    
            foreach ( $e->getError() as $error ) {
                echo $error, " <br />";
            }
        }
    }
    

    Classes Used

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

Sidebar

Related Questions

All, We have a PHP project in SVN. We develop code and do SVN
There is a project written in PHP that is just simply all procedural ...
Recently I tried to explain some poorly designed code to my project manager. All
We have a Library Project that we use for all our central reused code
I all, I just follow this great example: http://qt-project.org/doc/qt-4.8/tools-customcompleter.html I copy the code exactly
I have the following SVN structure: /Project1 /trunk ( Shared code between all clients
I'm working on a fairly large PHP project written in a procedural style (it
I was programming in php for a while but it was all procedural-oriented. Now
How would you structure a large project with most of the business logic already
I have a problem where I need to remove all code and triggers from

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.