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

  • SEARCH
  • Home
  • 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 7767493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:41:31+00:00 2026-06-01T15:41:31+00:00

I have recently begun working on a pre-existing PHP application, and am having a

  • 0

I have recently begun working on a pre-existing PHP application, and am having a bit of trouble when it comes to exactly what I should to improve this application’s scalability. I am from a C#.NET background, so the idea of separation of concerns is not new to me.

First off I want to tell you what exactly I am looking for. Currently this application is fairly well-sized, consisting of about 70 database tables and ~200 pages. For the most part these pages simply do CRUD operations on the database, rarely anything actually programmatically intensive. Almost all of the pages are currently using code akin to this:

$x = db->query("SELECT ID, name FROM table ORDER BY name");
if ($x->num_rows > 0) {
    while ($y = $x->fetch_object()) {
        foreach ($y as $key => $value)
            $$key = $value;

Obviously, this is not great for an application that is as large as the one I am supposed to be working on. Now I, being from a C#.NET background, am used to building small-scale applications, and generally building a small Business Object for each object in my application (almost a 1 to 1 match with my database tables). They follow the form of this:

namespace Application
{
public class Person
{

            private int _id = -1;
    private string _name = "";

    private bool _new = false;


    public int ID
    {
        get{ return _id; }
    }

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }


    public Person(int id)
    {
        DataSet ds = SqlConn.doQuery("SELECT * FROM PERSON WHERE ID = " + id + ";");

        if (ds.Tables[0].Rows.Count > 0)
        {
            DataRow row = ds.Tables[0].Rows[0];

            _id = id;

            _name = row["Name"].ToString();
        }
        else
            throw new ArgumentOutOfRangeException("Invalid PERSON ID passed, passed ID was " + id);         
    }

    public Person()
    {
        _new = true;
    }

    public void save()
    {
        if (_new)
        {
            doQuery(" INSERT INTO PERSON " +
                " ([Name]) " +
                " VALUES " +
                " ('" + Name.Replace("'", "''") + "'); ");
        }
        else
        {
            SqlConn.doNonQuery(" UPDATE PERSON " +
                " SET " +
                " [Name] = '" + _name.Replace("'", "''") + "' WHERE " +
                " ID = " + _id);
        }

    }

In shorter terms, they simply have attributes that mimic the table, properties, a constructor that pulls the information, and a method called save that will commit any changes made to the object.

On to my actual question: first of all, is this a good way of doing things? It has always worked well for me. Second, and more importantly, is this also a good way to do things in PHP? I’ve noticed already that PHP’s loose typing has caused me issues in the way I do things, also no method overloading is entirely new. If this isn’t a good practice are there any good examples of how I should adapt this project to 3 tiers? Or, possibly I should not attempt to do this for some reason.

I am sorry for the length of the question, but I have been digging on the internet for a week or so to no avail, all I seem to ever find are syntax standards, not structure standards.

Thanks in advance.

  • 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-01T15:41:33+00:00Added an answer on June 1, 2026 at 3:41 pm

    There are several patterns that one can follow. I like to use the MVC pattern myself. MVC is about splitting user interface interaction into three distinct roles. There are other patterns though, but for clarity (end length of the post I will only go into MVC). It doesn’t really matter which pattern you wish to follow as long as you use the SOLID principles.

    I am from a C#.NET background, so the idea of separation of concerns is not new to me.

    That’s great. Trying to learn PHP will only be an implementation detail at this point.

    Obviously, this is not great for an application that is as large as the one I am supposed to be working on.

    Glad that we agree 🙂


    In an MVC pattern you would have:

    Model: which does ‘all the work’
    View: which takes care of the presentation
    Controller: which handles requests

    When requesting a page it will be handled by the Controller. If the controller needs to get some work done (e.g. getting a user) it would ask the model to do this. When the controller has all the needed info it will render a view. The view only renders all the info.

    That person object you were talking about would be a model in the MVC pattern.

    I’ve noticed already that PHP’s loose typing has caused me issues in the way I do things

    PHP loose typing is pretty sweet (if you know what you are doing) and at the same time can suck. Remember that you can always do strict comparisons by using three = signs:

    if (1 == true) // truthy
    if (1 === true) // falsy
    

    also no method overloading is entirely new

    PHP indeed doesn’t really support method overloading, but it can be mimicked. Consider the following:

    function doSomething($var1, $var2 = null)
    {
        var_dump($var1, $var2);
    }
    
    doSomething('yay!', 'woo!'); // will dump yay! and woo!
    doSomething('yay!'); // will dump yay! and null
    

    Another way would be to do:

    function doSomething()
    {
        $numargs = func_num_args();
        $arg_list = func_get_args();
        for ($i = 0; $i < $numargs; $i++) {
            echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
        }
    }
    
    doSomething('now I can add any number of args', array('yay!', 'woo!', false));
    

    Or, possibly I should not attempt to do this for some reason.

    Of course you should attempt it. When you already have programming experience it shouldn’t be too hard.


    If you have any more questions you can can find me idling in the PHP chat tomorrow (I’m really need to get some sleep now 🙂 ).

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

Sidebar

Related Questions

I have recently begun working with QT and I'm having a small issue. I
I have recently begun delving into the world that is database programming with C++
I've recently begun learning C# but have encountered an annoying problem. Every variable I
I have recently upgraded my ASP.NET MVC application from beta to version 1. And
I have recently begun to use the EF v4 Code Only library for some
I have recently begun experiencing several odd issues with the Android SDK and I
I've recently begun working on Django and now my app is nearing completion and
I've recently begun working in an enterprise software environment with hundreds of different applications
I'm currently working on a game/engine that uses OpenGL for rendering, and recently have
I've recently begun a fairly small 2D project using SFML and TinyXML and have

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.