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

The Archive Base Latest Questions

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

There are some posts about this matter, but I didn’t clearly get when to

  • 0

There are some posts about this matter, but I didn’t clearly get when to use object-oriented coding and when to use programmatic functions in an include. Somebody also mentioned to me that OOP is very heavy to run, and makes more workload. Is this right?

Let’s say I have a big file with 50 functions. Why will I want to call these in a class? And not by function_name()? Should I switch and create an object which holds all of my functions? What will be the advantage or specific difference? What benefits does it bring to code OOP in PHP? Modularity?

  • 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. 2026-05-11T14:01:01+00:00Added an answer on May 11, 2026 at 2:01 pm

    In a lot of scenarios, procedural programming is just fine. Using OO for the sake of using it is useless, especially if you’re just going to end up with POD objects (plain-old-data).

    The power of OO comes mainly from inheritance and polymorphism. If you use classes, but never use either of those two concepts, you probably don’t need to be using a class in the first place.

    One of the nicest places IMO that OO shines in, is allowing you to get rid of switch-on-type code. Consider:

    function drive($the_car){      switch($the_car){        case 'ferrari':           $all_cars->run_ferrari_code();           break;        case 'mazerati':           $all_cars->run_mazerati_code();           break;        case 'bentley':           $all_cars->run_bentley_code();           break;     } } 

    with its OO alternative:

    function drive($the_car){      $the_car->drive(); } 

    Polymorphism will allow the proper type of ‘driving’ to happen, based on runtime information.


    Notes on polymorphism:

    The second example here has some premisses: That is that all car classes will either extend an abstract class or implement an interface.

    Both allow you to force extending or implementing classes to define a specific function, such as drive(). This is very powerful as it allows you to drive() all cars without having to know which one you’re driving; that is because they’re extending an abstract class containing the drive() method or implementing an interface forcing the drive() method to be defined.

    So as long as you make sure that all your specific cars either extend the abstract class car or implement an interface such as canBeDriven (both of which must declare the drive() method) you can just call the drive() method on an object which you know is a car (but not what type of car) without fear of it not being defined, as PHP will throw fatal errors at you until you define those methods in your specific car classes.

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

Sidebar

Related Questions

There are already quite some posts about the Singleton-Pattern around, but I would like
There are a couple of posts about this on Stack Overflow but none with
There are a few threads here at so about this matter but most of
There's some similar posts knocking about but I cant find anything that quite addresses
There are several tutorials and even some posts here about shrinking .war files. However,
Is there some way when sending this message to specify that I rather have
Is there some sort of C# directive to use when using a development machine
is there some way to tell sql server to use the (nolock) hint or
All right, I've seen some posts asking almost the same thing but the points
This question specifically relates to my experience with PHP, but there's no reason why

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.