Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

451.

What are the difference between abstract class and interface in OOPS?

Answer»

Thera are many differences between abstract CLASS and INTERFACE in php.

1. Abstract METHODS can declare with public, PRIVATE and protected. But in CASE of Interface methods declared with public.

2. Abstract classes can have constants, members, method stubs and defined methods, but interfaces can only have constants and methods stubs.

3. Abstract classes doest not support multiple inheritance but interface support this.

4. Abstract classes can contain constructors but interface doest not support constructors.

452.

What is "this"?

Answer»

It REFERS to the CURRENT OBJECT of a CLASS.

453.

What are the difference between overloading and overriding in oops?

Answer»

Overloading : It OCCURS when two or more METHODS in one class have the same METHOD name but different parameters.

Overriding : It means having two methods with the same method name and parameters. One of the methods is in the PARENT class and the other is in the child class.

454.

What is static keyword ?

Answer»

When a variable or function declared as STATIC then it cannot be accessed with an instantiated CLASS object. It is treats as PUBLIC if no visibility is defined. It can ALSO be used to define static variables and for late static bindings.

455.

What are the Final class and Final methods?

Answer»

Final CLASS- A class that can’t be extended and inherited further is known as Final Class. This class is declared with the keyword final and should be declared.

Final Method- METHODS in the final class are implicitly final and if a user uses the final keyword that means methods can’t be overridden by subclasses.

Example

class childClassname extends parentClassname {
    PROTECTED $numPages;

    public function __construct($AUTHOR, $pages) {
        $this->_author = $author;
        $this->numPages = $pages;
    }

    final public function PageCount() {
        return $this->numPages;
    }
}

456.

What is different types of Visibility?

Answer»

PHP have three access MODIFIERS such as public, private and protected.

  • public scope of this VARIABLE or function is available from ANYWHERE, other classes and instances of the object.
  • private scope of this variable or function is available in its own class only.
  • protected scope of this variable or function is available in all classes that EXTEND CURRENT class including the parent class.
457.

What is constructor and destructor?

Answer»

Constructor and Destructor both are SPECIAL functions which are automatically called when an object is created and destroyed.

Example

Constructor

class Animal

{

     public $name = "No-name animal";

     public function __construct() {

     ECHO "I'm ALIVE!";

}

}

Destructor

class Animal {

public $name = "No-name animal";

public function __construct($name) {

echo "I'm alive!";

$this->name = $name;

}

public function __destruct() {

echo "I'm dead now :(";

}

}

$animal = NEW Animal("Bob");

echo "Name of the animal: " . $animal->name;

 

458.

What is Polymorphism and its types in OOPS?

Answer»

Polymorphism is one of the core concepts which is used in object-oriented programming. Polymorphism generally shows the relationships between parent class objects and child class objects.

Types of polymorphism in OOPs
  • Compile Time Polymorphism- It is also known as Static Binding and allows the programmer to implement various methods. Names can be the same but their parameters should be different.
  • Runtime Polymorphism- It is also known as DYNAMIC Binding and allows the programmer to CALL a single overridden method during the runtime of the PROGRAM.
10. What is Inheritance?

It is a technique in which one class acquires the property of ANOTHER class. With the help of inheritance, we can reuse the fields and methods of the existing class.

Inheritance has three type, are given below.

  • Single inheritance
  • Multiple inheritance
  • Multi level inheritance

But PHP supports only single inheritance, where only one class can be derived from single parent class. We can also use multiple inheritance by using interfaces.

459.

What is Encapsulation in oops with an example?

Answer»

The process of binding up data and FUNCTIONS together that manipulates them is known as encapsulation in OOPS. It PROTECTS the data from outside interference and misuse.

Let’s understand the concept of encapsulation with both real-world examples and with the help of a program.

It is an attribute of an object, and it contains all data which is hidden. That hidden data is restricted to the members of that class.Example

class Account {
    private int account_number;
    private int account_balance;

    PUBLIC void show Data() {
        //code to show data
    }

    public void deposit(int a) {
        if (a < 0) {
            //show error
        } else
            account_balance = account_balance + a;
    }
}

460.

List out some of the differences between a class and an object?

Answer»
CLASSOBJECT
It is a blueprint from which different instances (objects) are created.Objects are the instances of the class.
Class is a LOGICAL entity.Objects are physical entities.
Users can DECLARE class only once.Objects can be declared MULTIPLE times depending upon the requirements.
When a class is created there is no memory allocationObjects allocated memory.
Class is a group of objects.Objects are real-world entities such as PEN, copy, mouse, etc.
Class can be declared using class keyword e.g class STUDENT {}Objects can be declared using the new keyword e.g. Student s1=new Student();
461.

What is virtual and pure virtual function?

Answer»
Virtual FunctionPure Virtual Function
Virtual Function has its definition HIDDEN in the Base classThey have no definition in the Base class.
The derived class can OVERRIDE the virtual function if required.In the case of a pure virtual function, the derived class has to override it.
If the derived class fails to override then it has the option to use the virtual function of the base classIt will THROW a compilation error if it fails to override pure virtual function.
462.

What is the difference between Method overriding and Method overloading?

Answer»
Method OverloadingMethod Overriding
It is the concept where we DEFINE two or more methods by the same name but with DIFFERENT signatures.In method overriding we define two or more identical methods which have the same name and signatures.
The binding of the method is DONE at compile time.The binding of the method is done at run time.
There are no class restrictions i.e. it can be ACHIEVED in the same or different classes.There are class restrictions in it i.e. it can only be achieved in different classes.
463.

What are the types of Class Variables?

Answer»

We have THREE DIFFERENT types of Class VARIABLES in OOPs.

1. LOCAL Variables

These types of variables are declared locally in methods, BLOCKS, and constructors. These variables are created when program control enters the methods, blocks, and constructor and are destroyed once program control leaves them.

2. Instance Variables

These variables are declared outside a block, constructor, or method. These are created once a class object is created and destroyed when the object is destroyed.

3. Static Variables

Static variables are also called class variables and are defined using the static keyword. These are declared within a class but outside a code block and a method. The creation of these variables starts when the program starts and is destroyed when the program ends.

464.

What is Class and Objects in OOPS?

Answer»

Class

In Object-Oriented PROGRAMMING, a class is a blueprint that defines the functions and variables which are common to objects of a certain kind.

Object

In OOPS an object is a specimen of the class. It is nothing but a component that CONSISTS of methods and properties which MAKE the data useful and help users to determine the behavior of the class.

Let’s UNDERSTAND this with an exampleExample

class Person{

    public $NAME;

    function __construct($name){

        $this->name = $name;

    }

    function getUserDetails(){

        return "My name is ".$this->name;

    }

}

465.

Why is object-oriented programming so popular?

Answer»

There are certain POINTS due to which OOPs become so popular.

  • It provides a better programming style, so you don’t need to write code again and again which you want to run, just make a CLASS of the OBJECT and call it.
  • As it supports the inheritance concept, an application created with OOPs can inherit another class property.
  • It provides a modularity model that means if you change any part of code that is in a SEPARATE module, that won’t impact any other module.
  • If you are stuck somewhere, this language allows your problems to break down into bite-sized pieces so that you can SOLVE them.
  • Due to its polymorphism feature, a single class can be used to create different objects, and that too from the same piece of code.
466.

Explain the difference between beforeRender() and beforeFilter() in cakePHP?

Answer»

beforeFilter() is executed before EVERY ACTION in the CONTROLLER call but beforeRender() is executed before the VIEW is rendered.

467.

What is Validation Model in CakePHP?

Answer»

CakePHP provide a very simple but powerful validation model so that we can easily manage our data validation. To do validation in CakePHP we can just need to declare a $VALIDATE array in your model class for REQUIRED fields.

Example


public $validate = array(
'email' => array(
'rule' => 'email',
'message' => 'Can you please enter a valid email ADDRESS.',
'required' => TRUE
),
'phone' => array(
'rule' => array('minLength', '10'),
'message' => 'Can you please enter a valid mobile number.',
'allowEmpty' => true
)
);

468.

What do you mean by Hooks in CakePHP ?

Answer»

These are the functions that we can call before and after doing any task in MODELS like after finding DATA, before SAVING data etc.
For EXAMPLE : beforeSave(), afterSave(), beforeFind(), afterFind().

469.

Explain the callback functions in CakePHP?

Answer»

Callback FUNCTIONS just before or after a CAKEPHP model OPERATION. These callback functions can be defined in model classes.These are very SIMPLE functions which CALLED automatically when are defined by the core CakePHP.

  • beforeFind()
  • afterFind()
  • beforeValidate()
  • afterValidate()
  • beforeSave()
  • afterSave()
  • beforeDelete()
  • afterDelete()
  • onError()
470.

What is the term "Security.salt" and "Security.cipherSeed" in CakePHP?

Answer»

Security.salt : It is used for GENERATING hashes. We can CHANGE it's default VALUE in /app/Config/core.php.
Security.cipherseed : It is used for encrypt/decrypt STRINGS. We can change it's default value by EDITING /app/Config/core.php.

471.

List some database related query function used in cakePHP.

Answer»
  • FIND()
  • findAll()
  • findAllBy()
  • findBy()
  • findNeighbours() ETC
472.

In cakePHP, which function is first executed before every action in the controller?

Answer»

beforeFilter()

473.

How we can call a model from view in cakePHP?

Answer»

APP::IMPORT('Model', 'PRICE');
$price = NEW Price();

474.

What do you mean by Scaffolding used in CakePHP?

Answer»

It is a technique that allows a user to define and CREATE a BASIC application that can create, RETRIEVE, update and delete objects in CAKEPHP.

475.

What do you mean by HABTM?

Answer»

It STANDS for "Has And BELONGS To Many" and it is a KIND of associations that can be defined in models for retrieving associated data ACROSS different entities in CAKEPHP.

476.

Please write the name of Cakephp database configuration file name and its location?

Answer»

It's DEFAULT file name is DATABASE.php.default. We can USE this file to CONFIGURE with database. This file is located in "/app/config/database.php.defaut".

477.

Explain the difference between Component, Helper, Behavior in cakePHP?

Answer»

COMPONENT : It is a Controller EXTENSION in cakePHP.
Helpers : Helpers are VIEW extensions in cakePHP.
Behavior : It is a Model Extension in cakePHP

478.

List some key features in cakaPHP 3 over cakePHP2?

Answer»
  • It improvements it's ORM feature.
  • It enhanced components and helpers
  • Best proficiency in cakePHP3
  • It improved SESSION MANAGEMENT in cakePHP3.
  • It improved consistency of CONVENTIONS in cakePHP3
  • It improved bug-fixing TOOL in cakePHP3
479.

How we can set custom page title in cakePHP?

Answer»

To SET a custom PAGE title, COPY & paste following code anywhere in your (.CTP) file.
$this->set("title_for_layout", "Home Page | bestinterviewquestion.com");

480.

How many types of caches does CakePHP support? Explain

Answer»
  • APCu
  • File-Based
  • Memcached
  • Redis
  • Wincache
  • XCache
481.

What is the default extension of view files? How we can change it?

Answer»

Default extension of view file is ".CTP".

We can change default extension to write public $EXT = '.yourextension' in AppController. If you WANT to change it for particular controller then please add it into that particular controller only. You can ALSO change it for the specific action of the controller by putting it in that action only.

482.

Can we use ajax in cakephp?

Answer»

YES, we can USE AJAX with by CALLING ajax HELPER.

483.

How we can get current URL in CakePHP?

Answer»

<?php ECHO Router::URL( $this-&GT;here, TRUE ); ?>

484.

How to pass multiple parameters to access into the view files?

Answer»

We can use $this-&GT;set(compact()) to PASS multiple PARAMETERS to ACCESS into the view file.Example

$this->set(compact('variable1','variable2','variable3'));

485.

How we can set layout in the controller file using cakePHP?

Answer»

$this-&GT;LAYOUT ="layout_name"; You can USE this in your CONTROLLER's ACTION.

486.

What do you mean by Component in cakephp? List some commonly used components.

Answer»

It is a class file that contains the common code and logic. It can be shared between the application's controllers. We can PERFORM various common tasks LIKE session handling, COOKIES and security related things with the HELP of COMPONENTS.

In CakePHP, we can use various components that are given below:-

  • Authentication
  • Cookie
  • Cross-Site Request Forgery
  • Flash
  • Security
  • Pagination
  • Request Handling etc
487.

What is a Helper and list some common helpers name used in cakePHP?

Answer»

It is the component like classes for the presentation layer of our APPLICATION. Helpers CONTAIN presentational logic that is shared between any views, elements, or layouts in cakePHP.

Most COMMON helpers used in cakePHP, is GIVEN below:-

  • FormHelper
  • HtmlHelper
  • JsHelper
  • CacheHelper
  • NumberHelper
  • Paginator
  • RSS
  • SessionHelper
  • TextHelper
  • TimeHelper etc
488.

How to use pagination in cakePHP?

Answer»

1. Open your controller FILE & put below code.
public $paginate = [
'limit' =&GT; 10,
'order' => [
'Users.name' => 'asc'
]
];


2. After this now load Paginator in initialize (). public FUNCTION initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
}


3. PLEASE set Paginate in Index function.
public function index() {
$this->layout=false;
$details=$this->Users->find('all');
$this->set('users', $this->paginate($details));
}


4. You can write this code in your "index.ctp" page.
echo $this->Paginator->prev('< ' . __('previous'), array('tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'disabled'), null, array('class' => 'prev disabled'));

echo $this->Paginator->numbers(array('separator' => '','tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'active'));
echo $this->Paginator->next(__('next').' >', array('tag' => 'li', 'currentTag' => 'a', 'currentClass' => 'disabled'), null, array('class' => 'next disabled'));
?>

 

489.

How to use session in cakePHP?

Answer»

It allows us to manage unique users across requests and also helps to stores data for specific users. We can access session from controllers, views, HELPERS, cells, and components.

We can use session in CAKEPHP in following WAYS :-

 

How to create session?

We can use the write() to create or write session.
Example : $session->write('username', 'bestinterviewquestion.com');

 

How to READ session?

We can use the read() to GET stored data from session.
Example : $session->read('username');

 

How to Check session?

We can use the check() to check this data is exists or not in session.
Example :

if ($session->check('username')) {
  // name exists and is not null.
}

 

How to delete session?

We can use the delete() to delete data from session.
Example : $session->delete('username');

 

How to destroy session?

We can use the destroy() to destroy session.
Example : $session->destroy();

490.

Why we used $this->set() in cakePHP?

Answer»

It is used for creating a VARIABLE in the view file with $this->set('variable1','bestinterviewquestion.com'); in CONTROLLER FIE and then that variable $variable1 will be available to use in the view template file for that action.

491.

What are the Server Requirements for installing cakePHP?

Answer»

CakePHP is QUITE simple and EASY to install.

  • HTTP Server should Have mod_rewrite is preferred.
  • PHP 5.6.0 or GREATER including PHP 7.2 (PHP latest version)
  • mbstring PHP extension
  • intl PHP extension
  • simplexml PHP extension

For more details you can visit cakePHP official WEBSITE Click here

492.

How to install cakePHP with composer?

Answer»

Composer is a tool USED for project dependencies.

To INSTALL CAKEPHP we can use
Execute this "php composer.phar create-project –prefer-dist cakephp/app MyProject"

493.

Write the latest version of cakePHP?

Answer»

CAKEPHP 3.7.2

494.

Explain CakePHP and why it is used?

Answer»

CakePHP is a modern, open-source PHP 7 framework that makes building WEB applications simpler and FASTER. It is BASED on MVC architecture that is powerful and quick to grasp. It is used to develop web applications.

2. What are the key features of cakePHP?Explain
  • Build APPS quickly
  • Complicated XML and YAML files not required.
  • Ideal for making commercial apps.
  • Secure, scalable and stable
  • Unique built-in features like translation, caching, database access, and authentication.
495.

How to enable the pretty URL format in Yii2?

Answer»

Create an .htaccess file and add this code.

RewriteEngine on

# If a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise FORWARD it to index.php

RewriteRule . index.php

2. Now Modify common/config/main-local.php

'urlManager' =&GT; [ 'class' => 'yii\web\UrlManager', 'showScriptName' => false, 'enablePrettyUrl' => true, 'rules' => array( '<controller:\W+>/<id:\d+>' => '<controller>/VIEW', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ), ],
496.

How to use asset Bundles in Yii?

Answer»

namespace appassets;

use yiiwebAssetBundle;

CLASS DemoAsset extends AssetBundle {

public $basePath = ‘@webroot’;

public $baseUrl = ‘@WEB’;

public $JS = [‘js/demo.js’];

}

497.

What is widgets in Yii? How we can use it?

Answer»

Widgets are INSTANCES of CWidget or their CHILD class. This component is primarily for PRESENTATIONAL purposes and is embedded in the view script to HELP generate a complex UI.

498.

How to use session in Yii?

Answer»

Create Session

Yii::APP()->session['name'] = "umesh singh";

Get VALUE from session

$name = Yii::app()->session['name'];

UNSET session like

unset(Yii::app()->session['name']);

Remove all session

Yii::app()->session->CLEAR();

Remove session from server

Yii::app()->session->DESTROY();

499.

How to use form validations in Yii?

Answer»
500.

List some database related query functions in Yii?

Answer»

22. How we can SET DEFAULT controller in YII?

You can set the default controller file through (protected/config/main.php).
array(
    'name'=&GT;'Yii Framework',
    'defaultController'=>'site',
)