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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:31:24+00:00 2026-06-04T14:31:24+00:00

So I have understood how interfaces and abstraction work in PHP, I just don’t

  • 0

So I have understood how interfaces and abstraction work in PHP, I just don’t see the point for example, of having a interface if it just sets a guide and requires implemented objects to have certain methods. Especially since the interface is not even getting instantiated.

This also goes with abstraction, I just can’t apply it to my code and see it as such a great thing. When I am trying to create objects on a bigger scale to interact with each other in order to figure out interfaces, each class ends up passing information back and forth, but never is the interface touched.

So what I’m asking is if you guys have any advice or links to outside sources that is good at explaining this kind of thing.

  • 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-04T14:31:25+00:00Added an answer on June 4, 2026 at 2:31 pm

    Here’s one simple example. Creating interfaces and abstract classes allows you to ensure an object adhears to a common API. See the example below.

    interface iCar
    {
        function drive();
    }
    
    abstract class Car implements iCar
    {
        public $make = 'Generic';
    
        public function drive()
        {
            printf("I'm driving in my %s%s", $this->make, PHP_EOL);
        }
    }
    
    class FordTruck extends Car
    {
        public $make = "Ford";
    }
    
    class Porsche extends Car
    {
        public $make = 'Porsche';
        public function drive()
        {
            printf("I'm speeding around in my %s%s", $this->make, PHP_EOL);
        }
    }
    
    class Yugo extends Car
    {
        public $make = 'Yugo';
    
        public function drive()
        {
            printf("I'm pushing my %s around town%s", $this->make, PHP_EOL);
        }
    }
    
    function drive(iCar $car)
    {
        $car->drive();
    }
    
    $car1 = new FordTruck;
    $car2 = new Porsche;
    $car3 = new Yugo;
    
    
    drive($car1);
    drive($car2);
    drive($car3);
    

    Even if you don’t specify the type of input parameter on the drive() function, you can check if the input is an instanceof an iCar

    function drive($car)
    {
        if ($car instanceof iCar)
            $car->drive();
    }
    

    Another example would be building a caching interface in your application. You can specify that all cache engines support the same methods for reading/writing/invalidating objects in the cache without knowing (or caring) about the actual implementation of a particular cache engine.

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

Sidebar

Related Questions

I'm just getting to grips with OOP PHP and while I have understood it
I just have a question regarding SimpleJSON's documentation. Is it implicit understood that functions
I have a question regarding interfaces. I understood that you cannot create instances of
I have two simple interfaces: public interface HasId<ID extends Serializable> extends Serializable { T
I understand that I cannot add preconditions on an interface implementation. I have to
As I have understood MVC, the logic for the model should also go into
I not sure I have understood all the principles of nosql, especially Cassandra project,
I always thought I understood how this works...but lately I have started really using
I have traditionally implemented a Model-View-Presenter [Passive View] like so: interface IView { string
I have an Java-Annotation that return a double value: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DoubleValue

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.