Click ⭐ if you like the project. Pull Requests are highly appreciated.
No. | Questions |
---|---|
1 | Class |
2 | Object |
3 | New |
4 | Constructor |
5 | Destructor |
6 | Inheritance |
7 | Parent class |
8 | Child class |
9 | Polymorphism |
10 | Data Abstraction |
11 | Encapsulation |
12 | Constants |
13 | Abstract Classes |
14 | Static Keyword |
15 | Final Keyword |
16 | What is interface & Why we need interface in PHP? |
17 | What is Traits & Why we use Traits? |
-
Class is the template which contains class members. class members are properties and methods. Property - Variable declared within the class. Method - Function declared within the class.
-
An object is the memory location of the class variables. We can access the class variables with the support of object.
-
By using this keyword we can allocate space in the new memory locations to load class content.
The constructor is one the type of method which is having class name same as method name.
By default, every class contains a default constructor used to load class constraints.
In PHP we can use constructor in two ways -
Using constructor keyword (default constructor) - __constructor().
Using class name - className().
**[⬆ Back to Top](#table-of-contents)**
-
Destructor is the special type of method, which can be executed at the time of destroying object of class. By using __destructor() we can create destructor. In PHP, the class objects will get destroyed when execution of the script is completed. We can also destroy class object between script execution using the unset function.
-
When a class is defined by inheriting the existing function of a parent class then it is called inheritance. Here child class will inherit all or a few member functions and variables of a parent class.
-
A class that is inherited from another class. This is also called a base class or superclass.
-
A class that inherits from another class. This is also called a subclass or derived class.
-
This is an object-oriented concept where the same function can be used for different purposes. For example, the function name will remain the same but it takes a different number of arguments and can do different tasks.
-
Any representation of data in which the implementation details are hidden (abstracted).
-
This refers to a concept where we encapsulate all the data and member functions together to form an object.
-
A constant is somewhat like a variable, in that it holds a value, but is really more like a function because a constant is immutable. Once you declare a constant, it does not change.
-
An abstract class is one that cannot be instantiated, only inherited. You declare an abstract class with the keyword abstract.
-
Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).
-
PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.
-
Interface is same like abstract class only difference is that interface dont have non abstract methods, It contains only abstaract methods. If we wont use all methods available in interface it will through fatal error.
An interface allows unrelated classes to implement the same set of methods, regardless of their positions in the class inheritance hierarchy. An interface enables you to model multiple inheritance because a class can implement more than one interface whereas it can extend only one class. Interfaces are 100% abstract classes – they have methods but the methods have no ‘guts’. Interfaces cannot be instantiated.
-
Traits are a simple group of methods that you want to include in another class. A Trait, like an abstract class, cannot be instantiated by itself. The trait is created to reduce the limitations of single inheritance in PHP by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.