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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:18:55+00:00 2026-05-12T07:18:55+00:00

I am kind of a slow learner I guess when it comes to coding,

  • 0

I am kind of a slow learner I guess when it comes to coding, I have been learning PHP for a couple of years and I still don’t understand Classes so it’s time I put some effort in to at least understanding them a little better.

I use functions for everything. People often make comments to me on here that they can’t believe I have a social network site and I don’t use classes.

I really do not understand the benefit of them can you explain the benefits besides it supposedly being easiar for multiple people to work on your code?

To me it seems like classes just complicate simple task

  • 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-12T07:18:55+00:00Added an answer on May 12, 2026 at 7:18 am

    Simply (in fact, extremely simply), classes allow you to organize code in logical units as well as provide containers and templates for user-created objects.

    Let’s say you have a car… A car can has a capacity and people inside.

    class Car {
        private $people = array();
        private $capacity;
    
        function __construct($capacity) { $this->capacity = $capacity; }
    
        function addPerson($name) {
            if(count($this->people) >= $this->capacity) {
                throw new Exception("Car is already at capacity");
            } else {
                $this->people[] = $name;
            }
        }
        function getPeople() { return $this->people; }
        function getCapacity() { return $this->capacity; }
    }
    

    Now, we can start using those cars:

    $aliceCar = new Car(2);
    $aliceCar->addPerson("Alice");
    
    $bobCar = new Car(4);
    $bobCar->addPerson("Bob");
    $bobCar->addPerson("Jake");
    

    I now have 2 cars (instances), which holds different data.

    echo implode(',', $aliceCar->getPeople()); // Alice
    echo $aliceCar->getCapacity(); // 2
    
    echo implode(',', $bobCar->getPeople()); // Bob,Jake
    echo $bobCar->getCapacity(); // 4
    

    I might also want to have a van, which will have an additional property for doors:

    class Van extends Car {
        private $num_doors;
    
        function __construct($capacity, $num_doors) {
            parent::__construct($capacity); // Call the parent constructor
            $this->num_doors = $num_doors;
        }
    
        function getNumDoors() { return $this->num_doors; }
    }
    

    Now let’s use that van:

    $jakeVan = new Van(7, 5);
    
    // Van is ALSO a Car
    $jakeVan->addPerson("Ron"); //Jake is with Bob now, so his son is driving the Van
    $jakeVan->addPerson("Valery") //Ron's girlfriend
    
    echo implode(',', $jakeVan->getPeople()); // Ron,Valery
    echo $jakeVan->getCapacity(); // 7
    echo $jakeVan->getNumDoors(); // 5
    

    Now maybe you can see how we could apply those concepts towards the creation of, for example, a DBTable and a User class.


    In fact, it’s hard to really start explaining why classes simplify one’s life without getting into the concepts of Object Oriented Programming (abstraction, encapsulation, inheritance, polymorphism).

    I recommend you read the following book. It will help you grasp the core concepts of OOP and help you understand why objects to really make your life easier. Without an understanding of those concepts, it’s easy to dismiss classes as just another complication.

    PHP 5 Objects, Patterns, and Practice

    PHP 5 Objects, Patterns, and Practice http://ecx.images-amazon.com/images/I/51BF7MF03NL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA240_SH20_OU01_.jpg

    Available at Amazon.com

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

Sidebar

Related Questions

I currently have a django site, and it's kind of slow, so I want
We have a couple of very very slow JUnit tests that make heavy use
A have setup an internal proxy kind of thing using Curl and PHP. The
I need to know what kind of things can make a php script slow.
Kind of a follow up to a question from yesterday. I have a hash
Kind of like this question I have many text snippets that I use many,
be kind this is my first post. I have a Crop intent retuning and
this is some kind of long post, so I have to say thanks for
Many PCs we have on the development team are out-dated and are very slow
is python exception slow? I'm kind using python exceptions to structure programm follow in

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.