Wed. Nov 20th, 2019

Codes

Codes for Coders

Session 1st Oops Interview questions and answer of PHP by Rishap Gandhi

2 min read
Session 1st Oops Interview questions and answer of PHP by Rishap Gandhi

Session 1st Oops Interview questions and answer of PHP by Rishap Gandhi

Session 1st of Oops Questions and Answer of PHP

Session 1st Oops Interview questions and answer of PHP by Rishap Gandhi
Session 1st Oops Interview questions and answer of PHP by Rishap Gandhi

What is Object Oriented Programming?

Object-oriented programming (OOP) is a programming language model which is organized around objects rather than actions and objects are instances of classes, which are used to interact with one another.

Goals of Object Oriented Programming:-
1. Ease of maintenance
2. Increasing Understanding.

What is data modeling?

In class, we create multiple get/set function to get and set the data through the protected functions known as Data Modeling.

class dataModel {    
    public function __set( $key, $value ) {
        $this->$key = $value;
    } 
}

What is difference between class and interface?

1) Interfaces do not contain business logic
2)You must extend interface to use.
3) You can’t create object of interface.

How Session – cookie works in PHP?
When a website open in new client machine(Browser), new sessionId is created and stored in php server and in client machine (In cookie).
All data is stored in PHP Server and cookie only had sessionId. When client send’s sessionId with request to the server, then server fetch the data corresponding to that sessionId and return to the browser.

What is Polymorphism?
It is simply “One thing, can use in different forms”
For example, One car (class) can extend two classes (honda & audi)

How to load classes in PHP.
We can load a class with the use of “autoload” class.
If we want to change from default function autoload to testautload function.
we can do this with “spl_autoload_register”

spl_autoload_register('kumar');

How to call parent constructor?

parent::__construct()

Are Parent constructors called implicitly when create an object of class?
No, Parent constructors are not called implicitly It must call this explicitly. But If Child constructors is missing then parent constructor called implicitly.

What happen, If constructor is defined as private OR protected.
If constructor declared as private, PHP through the following fatal error when createobject. Fatal error: Call to private BaseClass::__construct() from invalid context in. If constructor declared as private, PHP through the following fatal error when createobject. Fatal error: Call to protected BaseClass::__construct() from invalid context in

What happen, If New-Style constructor & old-style constructor are defined. Which one will be called.
New-Style constructor will called. But if New-Style constructor is missing, old style constructor will called.

What are different visibility of method/property?
There are 3 types of visibility of method & property and are following
Public: Can be accessed from same class method, child class and from outside of class.
Protected : Can be accessed from same class method, child class.
Private: Can be accessed from same class method only.

Leave a Reply

Your email address will not be published. Required fields are marked *