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

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The color brightwhite looks ok on my Emacs (which is… May 11, 2026 at 3:14 pm
  • added an answer You create an inner class because it is only ever… May 11, 2026 at 3:14 pm
  • added an answer You can use std::find_if algorithm, which will stop and return… May 11, 2026 at 3:14 pm

Related Questions

There are some posts about this matter, but I didn't clearly get when to
So we have this web app where we support UTF8 data. Hooray UTF8. And
I'm trying to parse the title tag in an RSS 2.0 feed into three
Where I'm at we have a software package running on a mainframe system. The
Recently I have been studying recursion; how to write it, analyze it, etc. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.