Is PHP an object-oriented language? To answer this question – No, PHP is not fully object oriented language; we can call “object-capable-language”. As the code written In PHP, You have to understand that just because we are using class it does not make it OOP , Especially if your code is mostly based on static class.
- Single Inheritance PHP allows a class definition to inherit from another class using the extend clause. Both member variable and member function are inherited.One of the main advantages of object-oriented programming is the ability to reduce code duplication with inheritance. Code duplication occurs when a programmer writes the same code more than once, a problem that inheritance strives to solve.
- Multiple Inheritances PHP doesn’t have multiple inheritances. If you have PHP 5.4, though, you can use traits to at least avoid every class having to copy code.
- ConstructorEvery class can have a constructors function. In PHP called _construct();Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
- DestructorPHP supports explicit destructors functions as of version 5.The destructor function of a class is always called _destruct();PHP destructor allows you to clean up resources before PHP releases the object from the memory.
- Encapsulation /Access Control PHP support public, private and protected variables and member function.
- PolymorphismPHP supports polymorphism in the sense of allowing instance of subclass to be used in place of parent instances. The correct member function will be dispatched to at runtime. The is no support for method overloading. Where dispatch happen based on function signature- each class only has one member function of a given name.
- Early Vs late Binding Two equally good answers are: The question doesn’t arise because of PHP being loosely typed and: All binding late. In PHP values are typed but variables are not. so there is no question about what method to call when the variable is of a different type than the value.
- Static Class /Function PHP offers static member variables and static method. It is possible to call a member function through scope resolution operator. Classname::function()
- Namespaces In the broadest definition namespaces are a way of encapsulating items. This can be seen as an abstract concept in many places. A Namespace works like a directory. You know how you can put files in a directory with the same names as files in the parent (or any other) directory? Well, a namespace lets you do that within an application for variables, functions and classes.