20 Interview questions for PHP Developer

php developer

Hello!! In today’s section we’re providing you some frequently asked PHP Interview Questions which will help you to win interview session easily. And if you’re an interviewer, Take the time to read the common interview questions you will most likely be asked.

  1. What is PHP?

PHP is a web language based on scripts that allow developers to dynamically create generated web pages. PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.

  1. What does PEAR stands for?

PEAR means “PHP Extension and Application Repository”. It extends PHP and provides a higher level of programming for web developers.

  1. How do you execute a PHP script from the command line?

Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:

php script.php

  1. Is multiple inheritance supported in PHP?

PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword ‘extended’.

  1. How can PHP and HTML interact?

It is possible to generate HTML through PHP scripts, and it is possible to pass pieces of information from HTML to PHP.

  1. What’s the difference between include() and require()?

If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

  1. Differences between GET and POST methods?

We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method.

  1. How to set & retrieve cookies in PHP?

To set: Setcookie(“sample”, “ram”, time()+3600);

To retrieve: echo $_COOKIE[“user”];

  1. What is the difference between Session and Cookie?

The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user’s computers in the text file format. Cookies can’t hold multiple variables while session can hold multiple variables. We can set expiry for a cookie, the session only remains active as long as the browser is open. Users do not have access to the data you stored in Session, since it is stored in the server. Session is mainly used for login/logout purpose while cookies using for user activity tracking

  1. What types of loops exist in php?

For, while, do while and foreach

  1. How can we connect to a MySQL database from a PHP script?

To be able to connect to a MySQL database, we must use mysqli_connect() function as follows:

<!–?php $database = mysqli_connect(“HOST”, “USER_NAME”, “PASSWORD”); mysqli_select_db($database,”DATABASE_NAME”); ?–>

  1. How can I display text with a PHP script?

Two methods are possible:

<!–?php echo “Method 1”; print “Method 2”; ?–>

  1. What is the static variable in function useful for?

A static variable is defined within a function only the first time, and its value can be modified during function calls as follows:

<!–?php function testFunction() { static $testVariable = 1; echo $testVariable; $testVariable++; } testFunction();        //1 testFunction();        //2 testFunction();        //3 ?–>

  1. What are SQL Injections, how do you prevent them and what are the best practices?

SQL injections are a method to alter a query in a SQL statement send to the database server. That modified query then might leak information like username/password combinations and can help the intruder to further compromise the server.

To prevent SQL injections, one should always check & escape all user input. In PHP, this is easily forgotten due to the easy access to $_GET & $_POST, and is often forgotten by inexperienced developers. But there are also many other ways that users can manipulate variables used in a SQL query through cookies or even uploaded files (filenames). The only real protection is to use prepared statements everywhere consistently.

  1. What’s the difference between unset()and unlink()

unset() sets a variable to “undefined” while unlink() deletes a file we pass to it from the file system.

  1. What are the main error types in PHP and how do they differ?

In PHP there are three main types of errors:

  • Notices– Simple, non-critical errors that are occurred during the script execution. An example of a Notice would be accessing an undefined variable.
  • Warnings– more important errors than Notices, however the scripts continue the execution. An example would be include() a file that does not exist.
  • Fatal– this type of error causes a termination of the script execution when it occurs. An example of a Fatal error would be accessing a property of a non-existent object or require() a non-existent file.
  1. What are Traits?

Traits are a mechanism that allows you to create reusable code in languages like PHP where multiple inheritance is not supported. A Trait cannot be instantiated on its own.

  1. Can the value of a constant change during the script’s execution?

No, the value of a constant cannot be changed once it’s declared during the PHP execution.

  1. Can you extend a Finaldefined class?

No, you cannot extend a Final defined class. A Final class or method declaration prevents child class or method overriding.

  1. What are the __construct()and __destruct() methods in a PHP class?

All objects in PHP have Constructor and Destructor methods built-in. The Constructor method is called immediately after a new instance of the class is being created, and it’s used to initialize class properties. The Destructor method takes no parameters.

Laravel interview questions and answers 2018

Laravel Interview questions and answers 2018 
Laravel is a powerful MVC PHP framework, designed for developers who need a simple and elegant toolkit to create full-featured web applications. Laravel was created by Taylor Otwell. This is a brief tutorial that explains the basics of Laravel framework.

Laravel is an open-source PHP framework, which is robust and easy to understand. It follows a model-view-controller design pattern. Laravel reuses the existing components of different frameworks which helps in creating a web application. The web application thus designed is more structured and pragmatic.

Laravel offers a rich set of functionalities which incorporates the basic features of PHP frameworks like CodeIgniter, Yii and other programming languages like Ruby on Rails. Laravel has a very rich set of features which will boost the speed of web development.

If you are familiar with Core PHP and Advanced PHP, Laravel will make your task easier. It saves a lot time if you are planning to develop a website from scratch. Moreover, a website built in Laravel is secure and prevents several web attacks.

Advantages of Laravel

Laravel offers you the following advantages, when you are designing a web application based on it −

  • The web application becomes more scalable, owing to the Laravel framework.
  • Considerable time is saved in designing the web application, since Laravel reuses the components from other framework in developing web application.
  • It includes namespaces and interfaces, thus helps to organize and manage resources.

Composer

Composer is a tool which includes all the dependencies and libraries. It allows a user to create a project with respect to the mentioned framework (for example, those used in Laravel installation). Third party libraries can be installed easily with help of composer.

All the dependencies are noted in composer.json file which is placed in the source folder.

1. What is Laravel?

Laravel is free open source “PHP framework” based on MVC design pattern. It is created by Taylor Otwell. Laravel provides expressive and elegant syntax that helps in creating a wonderful web application easily and quickly.

2. What are pros and cons of using Laravel Framework?

Pros of using Laravel Framework
  1. Laravel framework has in-built lightweight blade template engine to speed up compiling task and create layouts with dynamic content easily.
  2. Hassles code reusability.
  3. Eloquent ORM with PHP active record implementation
  4. Built-in command line tool “Artisan” for creating a code skeleton, database structure and build their migration
Cons of using laravel Framework
  1. The development process requires you to work with standards and should have a real understanding of programming
  2. Laravel is new framework and composer is not so strong in comparison to npm (for node.js)ruby gems and python pip.
  3. Development in laravel is not so fast in comparison to ruby on rails.
  4. Laravel is lightweight so it has less inbuilt support in compare to django and rails. But this problem can be solved by integrating third-party tools, but for large and very custom websites it may be a tedious task

    3. Explain Events in laravel ?

    An event is an action or occurrence recognized by a program that may be handled by the program or code. Laravel events provide a simple observer implementation, that allowing you to subscribe and listen for various events/actions that occur in your application.

    All Event classes are generally stored in the app/Events directory, while their listeners are stored in app/Listeners of your application.

    4. Explain validations in laravel?

    In Programming, validations are a handy way to ensure that your data is always in a clean and expected format before it gets into your database. Laravel provides several different ways to validate your application incoming data. By default Laravel’s base controller class uses a ValidatesRequests trait which provides a convenient method to validate all incoming HTTP requests coming from a client. You can also validate data in laravel by creating Form Request.
    click here read more about data validations in Laravel.

    5. How to install laravel via composer ?

    You can install Laravel via composer by running below command.

    composer create-project laravel/laravel your-project-name version
    

    6. List some features of laravel 5.0 ?

    • Inbuilt CRSF (cross-site request forgery ) Protection.
    • Inbuilt paginations
    • Reverse Routing
    • Query builder
    • Route caching
    • Database Migration
      • IOC (Inverse of Control) Container Or service container.

        7. What is PHP artisan. List out some artisan commands ?

        PHP artisan is the command line interface/tool included with Laravel. It provides a number of helpful commands that can help you while you build your application easily. Here is the list of some artisan command:-

        • php artisan list
        • php artisan help
        • php artisan tinker
        • php artisan make
        • php artisan –versian
        • php artisan make model model_name
        • php artisan make controller controller_name

        8. List some default packages provided by Laravel 5.4 ?

        Below are list of some official/ default packages provided by Laravel 5.4

        • Cashier
        • Envoy
        • Passport
        • Scout
        • Socialite

        9. What is named routes in Laravel?

        Named routing is another amazing feature of Laravel framework. Named routes allow referring to routes when generating redirects or Url’s more comfortably.
        You can specify named routes by chaining the name method onto the route definition:

        Route::get('user/profile', function () {
            //
        })->name('profile');
        
         You can specify route names for controller actions: 
        Route::get('user/profile', 'UserController@showProfile')->name('profile');
         Once you have assigned a name to your routes, you may use the route's name when generating URLs or redirects via the global route function: 
        // Generating URLs...
        $url = route('profile');
        
        // Generating Redirects...
        return redirect()->route('profile');
        

        10. What is database migration? How to create migration via artisan ?Migrations are like version control for your database, that allows your team to easily modify and share the application’s database schema. Migrations are typically paired with Laravel’s schema builder to easily build your application’s database schema.

        Use commands to create migration data via artisan.

        // creating Migration
        php artisan make:migration create_users_table
        

        Need More Question Comment Below 

Interactive Website – The Way of Winning the Internet!

Now a day, an Interactive website is the part of our era. You can win the internet with this. Today, in this article I’m going to show you how it Connivia Tech helps to win the Business on the internet.

  1. Easy to understand

If your website is informative or giving something knowledgeable then to increase the interest of reading that n keeping your visitor on your website for the maximum time it should be interactive. For that, you can add some interesting images related to information and videos which will be easy for users rather than reading everything. And it is easy to understand through videos.

  1. Helps to engage the customers on website

Getting hits on your website is one thing, however, having visitors invest time on your website gives considerably higher esteem. Interactive elements like galleries and online stores can encourage visitors to browse your goods and services, spending more time absorbing your brand and allowing your sales message to sink in.

  1. Easy to know customer’s interest

An interactive website can help you connect with your customers and build a loyal client base. It’s a lot easier to strengthen the relationships with clients that have already shown interest in any of your product or service this way. Essentially, you get the opportunity for conversation marketing as well as a targeted product placement.

  1. Great for getting customers feedback

Interactive features can help customers to make a decision, and they can provide a vessel for discovering how you are executing a business. Place a survey on your website and encourage your customers to rate you or leave reviews. Offer rewards in the form of discounts or other relevant incentives in order to get the quantity and quality of feedback you need—these can also be conveyed digitally through interactive elements.

  1. Helps to increase traffic n CTR

Not only a higher Google rank will help you to generate more traffic, but going interactive will generate web traffic from different web channels as well. Essentially, as you utilize emails, social media platforms, video streaming sites, etc. for interactive purposes, you’ll be able to spread the word about your business and reach your target audience more efficiently. The constant interactions and engaging communication with your customers, they’ll grow to trust your professionalism, expertise, and solutions. Therefore, a good interactive website can help you gain the necessary support from your target audience. Ultimately, the trust and support of your website visitors can encourage them to do business with you. It helps to increase your CTR (Click Through Rate). In that respect, an interactive website is a sure way to increased lead conversions.

In the end, for such benefits, you need to create a user-friendly and more functional website, which can be possible by working with professional web designers and developers. For expert solutions and such services contact on –  +91 9768161641. You’ll also get the effective SEO & SMM plan with valuable content to grow your online business efficiently.