0% found this document useful (0 votes)
4 views

Interview Copy

The document provides a comprehensive overview of PHP and Laravel, including key concepts, functions, and differences between various elements in PHP. It covers topics such as PHP sessions, error handling, object-oriented programming, and Laravel's features like Artisan, middleware, and relationships. Additionally, it highlights the latest Laravel version and the advantages of using the framework for web application development.

Uploaded by

gujjuesports07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Interview Copy

The document provides a comprehensive overview of PHP and Laravel, including key concepts, functions, and differences between various elements in PHP. It covers topics such as PHP sessions, error handling, object-oriented programming, and Laravel's features like Artisan, middleware, and relationships. Additionally, it highlights the latest Laravel version and the advantages of using the framework for web application development.

Uploaded by

gujjuesports07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PHP Interview Question Answer

founder of php Rasmus Lerdorf


What is PHP? PHP is a web language based on scripts that allow developers to dynamically create generated web pages.
A session in PHP is a way to store information to be used across multiple pages of an entire website. The information is not stored on the user’s computer,
unlike cookies. In a temporary directory on the server, a file will be created by the session where registered session variables and their values are stored. This
What is a session in PHP? information will be available to all pages on the site during that visit.
What are the different types of Array in PHP? Indexed Array , Associative Array , Multidimnsional Array
Explain the main types of errors. Notice , Warining , Error , Fatal
The foreach statement is a looping construct that is used in PHP to iterate and loop through the array data type.

The working of foreach is simple, with every single pass of the value, elements get assigned a value, and pointers are incremented. This process is
How does the ‘foreach’ loop work in PHP? repeatedly done until the end of the array has been reached.
GET method is used for requesting data from a specified resource.
POST is used for sending the data to the server as a package in a separate communication with the processing script.
GET Method can be used for submitting the form where the user can bookmark the result.
Submissions by form with POST cannot be bookmarked.
GET method only for data that is not secure.
POST Data sent through this method is secure.
GET method is not safer since parameters may be stored in web server logs or browser history.
Differentiate between GET and POST POST method is safer than GET because the parameters are not stored in web server logs or browser history.
What is the difference between single Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain
quoted string and double quoted string? character sequences
Echo can output one or more string but print can only output one string and always returns 1.
What is the difference between “echo” and
“print” in PHP? Echo is faster than print because it does not return any value
ereg() – The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false
otherwise.
split() – The split() function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in string.
preg_match() – The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.
String some of the functions in PHP preg_split() – The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
include() function

This function is used to copy all the contents of a file called within the function, text wise into a file from which it is called.
When the file is included cannot be found, it will only produce a warning (E_WARNING) and the script will continue the execution.

require() function:

The require() function performs same as the include() function. It also takes the file that is required and copies the whole code into the file from where
What is the difference between the include() the require() function is called.
and require() functions? When the file is included cannot be found, it will produce a fatal error (E_COMPILE_ERROR) and terminates the script
In PHP, @ is used for suppressing error messages. If any runtime error occurs on the line which consists @ symbol at the beginning, then the error will be
What is the purpose of @ in PHP? handled by PHP
Explain the difference between $message $message is used to store variable data. $$message can be used to store variable of a variable. Data stored in $message is fixed while data stored in
and $$message? $$message can be changed dynamically
JavaScript is a client-side programming language, whereas PHP is a server-side scripting language. PHP has the ability to generate JavaScript variables,
Does JavaScript interact with PHP? and this can be executed easily in the browser. Thereby making it possible to pass variables to PHP using a simple URL
PHP constructor and destructor are special type functions which are automatically called when a PHP class object is created and destroyed. The
constructor is the most useful of the two because it allows you to send parameters along when creating a new object, which can then be used to initialize
What are constructor and destructor in PHP? variables on the object.
An Object-Oriented programming (OOP) language will have object-oriented features such as Abstraction, Encapsulation, Inheritance, polymorphism etc.,
What is OOP and how PHP is an object- PHP was primarily based on C++ programming language which is an object-oriented programming language. A PHP class contains properties and
oriented language? methods which are used to create an object of that class and each object will have its own properties and values.
A Namespace in PHP is used to encapsulate the items which are similar to that of abstraction in Object Oriented programming concepts. Namespaces are
used to establish a relationship among classes, functions, and constants. A Namespace can be defined using the keyword The namespace keyword is
What is a Namespace in PHP? reserved in PHP for its internal use to avoid conflict with the user created identifiers.
The final keyword in PHP is used to mark either a class or a function as final. If a class is marked as final, it cannot be extended to use its properties or
What is a final keyword in PHP and when it is methods. It prevents its child classes from overriding a method. If only a function is marked as final, then it can’t be extended. The final keyword was
used? introduced in PHP 5 version. A final declaration can be done by prefixing the class name or function name with the final keyword
A class is a template for an object, a user-defined datatype that contains variables, properties, and methods.

What is a class? Class represents all properties and behaviors of object.


Objects are created from Classes, is an instance of a class that is created dynamically.

What is an object? Object in programming is similar to real word object. Every programming object has some properties and behaviors.
public: Public method or variable can be accessible from anywhere, Means a public method or variable of a class can be called outside of the class or in
a subclass.
What is different types of Visibility? OR What protected: A protected method or variable can only be called in that class & it's subclass.
are access modifiers? private: A private method or variable of a class can only be called inside that class only in which it is declared.
Method overriding allows a subclass to command the implementation of a method that can override in the main class. The implementation thus given will
What do you mean by method overriding? override by the same method name, same variable, and same return type. Overloading is a Static Binding that has the same method with different
Differentiate between overloading and arguments. This may or may not return the equal value within the same class on its own. Why overriding is a dynamic binding process with the same
overriding. method names with the same arguments and return type associated with the class and its subclass.
An exception is a situation that arises during the execution of any program. These are of two types-runtime exception and error exceptions. These
What do you mean by exception handling? exceptions are handled through 3 exception handling mechanisms-try, catch and throw keywords.
What is the purpose of break and continue Break – It terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.
statement? Continue – It causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
How do you execute a PHP script from the command
php {filename}
line? => php script.php
How is the comparison of objects done in PHP?We use the operator ‘==’ to test is two objects are instanced from the same class and have same attributes and equal values. We can test if two objects are referring to the same instance of the same class by the use of the identity operator ‘===’.
Differentiate between == and === The difference between == and === is that: == converts the variable values to the same type before performing comparison. This is called type coercion. === does not do any type conversion (coercion) and returns true only if both values and types are identical for the two variables being compared
try - A function using an exception should be in a "try" block. If the exception does not trigger, the code will continue as normal. However if the exception triggers, an exception is "thrown"
throw - This is how you trigger an exception. Each "throw" must have at least one "catch"
Differentce betwwen Try, throw and catch catch - A "catch" block retrieves an exception and creates an object containing the exception information
what is error handling in php Error handling is the process of catching errors raised by your program and then taking appropriate action. If you would handle errors properly then it may lead to many unforeseen consequences. Its very simple in PHP to handle an errors.

Laravel Interview Question Answer


founder of laravel tylor otwel
Laravel is an open-source widely used PHP framework. The platform was intended for the development of web application by using MVC architectural
What is Laravel? pattern. Laravel is released under the MIT license
What is the latest Laravel version? The latest Laravel version is version 10, which was released on September 8th, 2020.
Define Composer. Composer is the package manager for the framework. It helps in adding new packages from the huge community into your laravel application.
Artisan is the command-line tool for Laravel to help the developer build the application. You can enter the below command to get all the available
commands:

PHP artisan list: Artisan command can help in creating the files using the make command. Some of the useful make commands are listed below:

php artisan make:controller - Make Controller file

php artisan make:model - Make a Model file

php artisan make:migration - Make Migration file

php artisan make:seeder - Make Seeder file

php artisan make:factory - Make Factory file

php artisan make:policy - Make Policy file

What is an artisan? php artisan make:command - Make a new artisan command


The environment variables can be defined in the .env file in the project directory. A brand new laravel application comes with a .env.example and while
installing we copy this file and rename it to .env and all the environment variables will be defined here.

How to define environment variables in Some of the examples of environment variables are APP_ENV, DB_HOST, DB_PORT, etc.
Laravel?
Maintenance mode is used to put a maintenance page to customers and under the hood, we can do software updates, bug fixes, etc. Laravel applications
can be put into maintenance mode using the below command:

php artisan down

And can put the application again on live using the below command:

php artisan up
How to put Laravel applications in
maintenance mode? Also, it is possible to access the website in maintenance mode by whitelisting particular IPs.
What is HTTP middleware? HTTP middleware is a technique for filtering HTTP requests. Laravel includes a middleware that checks whether application user is authenticated or not.
App/: This is a source folder where our application code lives. All controllers, policies, and models are inside this folder.
Config/: Holds the app’s configuration files. These are usually not modified directly but instead, rely on the values set up in the .env (environment) file at the
root of the app.
Explain important directories used in a Database/: Houses the database files, including migrations, seeds, and test factories.
common Laravel application Public/: Publicly accessible folder holding compiled assets and of course an index.php file.
Laravel traits are a group of functions that you include within another class. A trait is like an abstract class. You cannot instantiate directly, but its methods
Explain traits in Laravel. can be used in concreate class
Laravel has blade template engine to create dynamic layouts and increase compiling tasks.
Reuse code without any hassle.
Laravel provides you to enforce constraints between multiple DBM objects by using an advanced query builder mechanism.
The framework has an auto-loading feature, so you don’t do manual maintenance and inclusion paths
The framework helps you to make new tools by using LOC container.
What are the advantages of using Laravel? Laravel offers a version control system that helps with simplified management of migrations.

List available types of relationships in


Laravel Eloquent. one to one, one to many, many to one, many to many
Define Lumen Lumen is a micro-framework. It is a smaller, and faster, version of a building Laravel based services, and REST API’s.
Name databases supported by Laravel. PostgreSQL , SQL Server , SQLite , MySQL
What are common HTTP error codes? 401, 404, 301
What is the use of dd() function? Dump and Die. This function is used to dump contents of a variable to the browser.
php artisan make:controller - Make Controller file
php artisan make:model - Make a Model file
php artisan make:migration - Make Migration file
php artisan make:seeder - Make Seeder file
php artisan make:factory - Make Factory file
What is PHP artisan. List out some artisan php artisan make:policy - Make Policy file
commands ? php artisan make:command - Make a new artisan command
What is an artisan? Artisan is the command-line tool for Laravel to help the developer build the application
How to implement soft delete in Laravel? not delete data from table just add delete time stamp
What is throttling and how to implement it in Throttling is a process to rate-limit requests from a particular IP. This can be used to prevent DDOS attacks as well. For throttling, Laravel provides a
Laravel? middleware that can be applied to routes and it can be added to the global middlewares list as well to execute that middleware for each request.
View file name store with which extension?
And why this extension needed? viewfilename.blade.php .blade extension used for security puopose.
What does ORM stand for? Object Relational Mapping
In the past, you may have written a cron configuration entry for each task you needed to schedule on your server. However, this can quickly become a pain
because your task schedule is no longer in source control and you must SSH into your server to view your existing cron entries or add additional entries.
What is task scheduling in laravel? Laravel's command scheduler offers a fresh approach to managing scheduled tasks on your server
Facades are a way to register your class and its methods in Laravel Container so they are available in your whole application after getting resolved by
Reflection.The main benefit of using facades is we don’t have to remember long class names and also don’t need to require those classes in any other class
What are facades? for using them. It also gives more testability to the application.
Below are the four default route files in the routes folder in Laravel:

web.php - For registering web routes.


api.php - For registering API routes.
console.php - For registering closure-based console commands.
What are the default route files in Laravel? channel.php - For registering all your event broadcasting channels that your application supports.
Seeders in Laravel are used to put data in the database tables automatically. After running migrations to create the tables, we can run `php artisan db:seed` to run the seeder to populate the database tables.

We can create a new Seeder using the below artisan command:

What are seeders in Laravel? php artisan make:seeder [className]


Relationships in Laravel are a way to define relations between different models in the applications. It is the same as relations in relational databases.

Different relationships available in Laravel are:

One to One
One to Many
Many to Many
Has One Through
Has Many Through
One to One (Polymorphic)
One to Many (Polymorphic)
Many to Many (Polymorphic)
What are Relationships in Laravel? Relationships are defined as a method on the model class. An example of One to One relation is shown below.
In Laravel, Events are a way to subscribe to different events that occur in the application. We can make events to represent a particular event like user logged in, user logged out, user-created post, etc. After which we can listen to these events by making Listener classes and do some tasks like, user logged in then make an entry to audit logger of application.

For creating a new Event in laravel, we can call below artisan command:

What are Events in Laravel? php artisan make:event UserLoggedIn


How to do request validation in Laravel? Request validation in laravel can be done with the controller method or we can create a request validation class that holds the rules of validation and the error messages associated with it.
What is a Service Container in Laravel? Service Container or IoC in laravel is responsible for managing class dependencies meaning not every file needs to be injected in class manually but is done by the Service Container automatically. Service Container is mainly used in injecting class in controllers like Request object is injected. We can also inject a Model based on id in route binding.
A Service Provider is a way to bootstrap or register services, events, etc before booting the application. Laravel’s own bootstrapping happens using Service Providers as well. Additionally, registers service container bindings, event listeners, middlewares, and even routes using its service providers.

What is a Service Provider? If we are creating our application, we can register our facades in provider classes.
What are collections? Collections in laravel are a wrapper over an array of data in Laravel. All of the responses from Eloquent ORM when we query data from the database are collections (Array of data records).
What is dependency Injection in Laravel? The Laravel Service Container or IoC resolves all of the dependencies in all controllers. So we can type-hint any dependency in controller methods or constructors. The dependency in methods will be resolved and injected in the method, this injection of resolved classes is called dependency Injection.
What are accessors and mutators? Accessors are a way to retrieve data from eloquent after doing some operation on the retrieved fields from the database. For example, if we need to combine the first and last names of users but we have two fields in the database, but we want whenever we fetch data from eloquent queries these names need to be combined.

git stage
git add .
git commit
git push
git merge
git clone
command for run seeder / migration
how to create/edit new migration
where is show laravel version composer.json
how to run laravel project

operators
what is class /object / array
types of array
string function array function s
why choose laravel not gaming
about project shivam cars

datatypes
last second record select *from secondLastDemo order by StudentId DESC LIMIT 1,1;
insert update delete
default date format
enum

You might also like