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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:53:45+00:00 2026-05-26T07:53:45+00:00

The biggest advantage of the OOP vs procedural programming in PHP to my understanding

  • 0

The biggest advantage of the OOP vs procedural programming in PHP to my understanding is the sort of separation of the function names (sort of namespace).

So now when we have namespace since version 5.3, what do you think – For most cases (small to mid websites), when we need fast and again structured code, do the use of namespace + prodecural programming gains signifficant advantage over defining and writing in OOP.

Advantages:

  • structured
  • faster code/development
  • again we can define something like private functions within the namespace starting with “_” knowing that we don’t need to use them
  • etc..

Code example:

namespace User;

function setPassword ($user_id) {

    $pass = _generatePassword();

    $sql = 'UPDATE `users` SET `password` = '.escape($pass).' WHERE `user_id` = '.escape($user_id);
    $result = mysql_query($sql);


    if (mysql_affected_rows() == 1) return $sql;
    else return $sql;
}

function _generatePassword () {

    $char = '0123456789abcdefghijklmnopqrstuvwxyz';
    $str = '';
    for ($i = 1; $i <= 6; $i++) {
        $str .= $char[mt_rand(0, strlen($char))];
    }

    return $str;
}

Usage:

$user_id = 5;
User\setPassword($user_id);

I am asking for opinion. I know that it is just to the developers style, but maybe I am missing something.

PS. For most cases (small to mid websites) – I mean when you do websites for clients which are mostly 1 time development, and a little feature improvements in the long run.

  • 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-26T07:53:46+00:00Added an answer on May 26, 2026 at 7:53 am

    You are thinking of OOP the wrong way. If you are trying to compare OOP with procedural namespaces merely as two different ways of organizing your code and function calls then certainly namespaces will seem more efficient.

    The advantage of OOP isn’t in organizing an object full of functions. That just treats OOP classes as big “utils” classes full of functions. The advantage of OOP isn’t organizational. It is an entirely different way of building your programs that causes you to break your code into smaller, discreet entities. I use OOP in all of my PHP programs, even for small projects.

    The advantage of OOP becomes most clear for me when doing any project that accesses a database (which is pretty well everything nowdays). I create small classes to model each database table and then access the information in these tables as objects. I have some base classes I use in all my projects that define how to map tables to objects so I don’t retype or paste mysql commands any more. I just use the objects and they inherit all the needed functionality for inserting, updating and deleting from the database.

    It sure is far more useful in code (especially if you use a PHP ide that has code completion) to see this in code:

    echo "Hello, {$someDataObject->name}!";
    

    Than this:

    echo "Hello, " . $row['name'] . "!";
    

    The difference might not be obvious right away. Both examples are a single line of code to print a table column. But the second example requires that I know the column names in my head. The first example has the column names embedded in the classes as properties. My code inspector knows all the properties so when I code it presents a list of all the properties as I type.

    Maintaining the classes is easier than you think. Depending on the object framework you choose there are scripts to generate classes from tables and keep them up to date. And I find it FAR less error and bug prone to keep my object classes up to date myself than to have database changes break code because column names changed and then I have to update those column references in dozens of places. Yes, there is search and replace, but do you see the advantage of updating one file for your column change than updating every reference to $row[‘some_column’]?

    I hope this helps answer your question.

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

Sidebar

Related Questions

the biggest problem I have is understanding why some of my code wont work
I have a loop that is my biggest time suck for a particular function
One of the biggest advantages of object-oriented programming is encapsulation, and one of the
One of the biggest issues I have, from a UI standpoint, when building a
Generally the database server is the biggest, most expensive box we have to buy
One of biggest interest right now is iPhone development. I'm fixing to start putting
Right now the biggest issue I'm having with using AJAX is the fact that
I've got a column called description of type NVARCHAR(MAX) - biggest you can have.
Possible Duplicate: Biggest advantage to using ASP.Net MVC vs web forms I was reading
One of the biggest issues I have with haskell is to be able to

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.