Skip to content

rohansanghai/object-oriented-programming-contents-in-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 

Repository files navigation

Object oriented programming contents in PHP

Click ⭐ if you like the project. Pull Requests are highly appreciated.

Table of Contents


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?
  1. Class

    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.

    ⬆ Back to Top

  2. Object

    An object is the memory location of the class variables. We can access the class variables with the support of object.

    ⬆ Back to Top

  3. New

    By using this keyword we can allocate space in the new memory locations to load class content.

    ⬆ Back to Top

  4. Constructor

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)**
  1. Destructor

    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.

    ⬆ Back to Top

  2. Inheritance

    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.

    ⬆ Back to Top

  3. Parent class

    A class that is inherited from another class. This is also called a base class or superclass.

    ⬆ Back to Top

  4. Child Class

    A class that inherits from another class. This is also called a subclass or derived class.

    ⬆ Back to Top

  5. Polymorphism

    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.

    ⬆ Back to Top

  6. Data Abstraction

    Any representation of data in which the implementation details are hidden (abstracted).

    ⬆ Back to Top

  7. Encapsulation

    This refers to a concept where we encapsulate all the data and member functions together to form an object.

    ⬆ Back to Top

  8. Constants

    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.

    ⬆ Back to Top

  9. Abstract Classes

    An abstract class is one that cannot be instantiated, only inherited. You declare an abstract class with the keyword abstract.

    ⬆ Back to Top

  10. Static Keyword

    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).

    ⬆ Back to Top

  11. Final Keyword

    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.

    ⬆ Back to Top

  12. What is interface & Why we need interface in PHP?

    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.

    ⬆ Back to Top

  13. What is Traits & Why we use Traits?

    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.

    ⬆ Back to Top

About

Object oriented programming contents in PHP

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published