Skip to content
 

PHP Interview Questions and Answers

PHP Interview Questions and Answers Tutorials Jobs

 

1.Q:What difference there is between these three ways of printing out strings: print, printf and echo?

A: a)print- being a construct, we don’t really have to use the parentheses at calling it, the values returned are TRUE in case the output is a success and FALSE  when the printing failed. It doesn’t use many parameters.

b)printf-being a function gives a formatted output but it is slower than print or echo.

c)echo-this is the most primitive, fastest(but not at such a high degree) and accepts multiple parameters, it could be excluded from the next PHP versions.

 

2. Q:How did you get accustomed to PHP?

A: When answering to this question, an answer like: “Money is the purpose of learning PHP.” Is the worst thing, even if this sentence is true, don’t fall into this trap. Even if we think that money is the true purpose it may not be. We can say that, while playing an online RPG we looked for automated ways of calculating talents or something and every other coding languages didn’t have the necessary abilities or were not compatible with our type of learning. We can add how passionate we are about PHP and that this is more than a job for us.

 

3.Q: What is the meaning of Cross Site Scripting?

A: XSS or Cross Site Scripting makes a link that looks trustworthy an attack with malicious code (security exploit), when the user clicks this link the program enters the user’s machine like it was requested by the user and executes. It is meant for information theft.

 

4.Q: What meaning has a Persistent Cookie?

A:The cookie that can be stored on the user’s computer inside a cookie file in a permanent way is named a Persistent Cookie. Usually cookies are temporary creations and they are not stored on the machine, but on the memory of a browser. They are deleted at the closing of the browser. Normal (temporary) cookies and persistent one are used in different circumstances as follows:

- normal cookies are not for keeping information on a long term.

-persistent cookies are exactly used for long term information.

-normal cookies can only be accessed by the browser, so this means they are more secure.

-persistent cookies are not safe because their values can be viewed by users.

 

5.Q: What types of runtime errors exist in PHP?

A: Runtime errors in PHP have three distinct categories according to how severe they are:

a)notices-these errors are non-critical and trivial and are found at script executions , for instance, when trying to access an undefined variable. This type of error is totally invisible to the user.

b)warnings-a more severe type of error, for instance if we try to include() a non-existing file. This type of error can be viewed by the user but the script still runs.

c)fatal errors-the most severe of all, for instance, when we try to instantiate an object from a class that doesn’t exist or we invoke a function that doesn’t exist. This type of error is displayed immediately by PHP to the user and the script stops.

 

6. Q: What is the purpose of using sha1() or crc32() if they are not as safe as md5() when we talk about generating hashes?

A: Encrypting in PHP is not free at all, but it has the advantage of simplicity. The reason for not using md5() is sometimes the space occupied by a 160 bit value. 32 bit values occupy less space in the database. There is another good reason and that is the slow speed of hash value delivery when the encryption is stronger. High volumes are much slower.

 

7. Q: is there a big difference when we talk about the methods POST and GET and what are the different usage cases involved?

A: The difference between these comes from where is the submission stored. The Get method submits data and then the data is stored by using $_GET array. On the other hand the POST method submits data and it is stored by the $_POST array. The browser’s field of address contains the data submitted by GET and the data submitted by POST will be found in another region of the browser. Another difference is the small amount of stronger data(GET) versus the bigger amount of sensitive data (POST) that can be submitted.

 

8. Q:How do we describe each of these functions: include, include_once or require?

A: With include, a file can be included multiple times, with include_once a file can only be include one time( the next calls of this function will become ignored) and we will not have any more reassignment or redefinition problems, require will stop in the case of failure but include is different in the way that it continues when errors appear.

 

9.Q: What does CAPTCHA mean?

A: The initials of CAPTCHA refer to Completely Automated Public Turing Test to tell Computers and Humans Apart. It is a measure of security, an anti-bot feature. Bots are sometimes used for the automatic filling of forms for the purpose of spam. The program that deals with this will present a string of distorted numbers or letters or a combination of these two and the string is contained in an image file, which are unreadable by computers because of the distortion. Humans can read the characters even if they are distorted so the insertion of those characters is required in the validation field in order to use the application.

 

10. Q:How can we verify if a user is logged in or not in the shape of a function that will be used on every page and return to the current page after logging in?

A: There is an object that can be used to achieve this:  $_SESSION. When the user login process is made they are verified for correctness and if they appear as valid they will be stored in a session. After that we can check if the variable is set in one file or not, the file will be included then in all the pages.

 

11.Q: Can we describe $_session against session_register?

A: Session_register is a function which returns a Boolean value and when register_global is not activated it can’t work. $_session is a function which is returning a string value and can work independent, meaning that it doesn’t depend on the activation of register_global. These functions both are used for the manipulation of variables but $_session is a better choice.

 

12.Q: What use has the friend function in PHP?

A:A friend function is a function that is shared between various classes no matter if they are member functions, global functions or single class. They can become friends of classes with the aid of a specifier-the friend specifier in the class in which they are allowed to exist. Atribbutes of a class that chose them as their  friend can be used by the function.

 

13.Q: What is the meaning of htaccess, why are we using it and where?

A: Files with the .htaccess extension are used by the Apace Server that can help us make modifications to directories.

14.Q: How can we increase the performance of our written script?’

A: Increasing performance of a script can depend on many factors, for example if we have a database involved we must make new queries that have bigger performance, then we must make the fine tuning that is required. We will not use aliases in PHP because native functions are better and from these we must choose the best of them, according to our needs. For making simple string replaces, str_replace is better than ereg_replace, is_int() but not is_integer. For script profiling we should use DBG or xdebug.

 

15. Q:How do we describe cron jobs?

A: A cron job is a program that helps us to schedule command execution in an automatic way at different times or dates. It is often used by system administrators for backups  but the possible usages are unlimited, for example we can use it to connect to the web and download emails.

 

16.Q: In what way is Return URL different from Notify URL?

A: A Return URL is that URL to which we are going after we made an online payment, for instance we are taken to a page where it is written:” The payment is complete. Thank you”. A Notify URL is the URL used for example by Paypal for putting transaction information.

 

17. Q:Can we run a PHP script from command line?

A: Yes this is possible since the version 4.3.0 of PHP when a fresh SAPI was implemented(Server Application Programming Interface) called CLI or Command Line Interface. We must run CLI and write as argument the name of the PHP script. For instance: “php anyScrypt.php”, the command line is “php” and it is used for calling CLI. There is one interface that doesn’t fully support command line and that is Web CGI.

 

18. Q:Is it possible to write “xyz.PHP” double time in the “index.PHP” page?

A: Yes, “xyz.PHP” can be written more than once in all pages, but there is an issue when it contains declarations of functions because they will conflict with other already made declarations, otherwise there is no issue in displaying the same content twice in a page.

 

19. Q:What role has the function header() in PHP?

A: By using the header() function in PHP a raw HTTP header is transmitted to the client . This function can also be used for page redirecting. But it mustn’t be declared after an output.

 

20. Q:What is the meaning of session_set_save_handler() ?

A: session_set_save_handler() is used for the functions that store of retrieve session data, it handles these functions at the user-level. It is used as an alternative to the default PHP storage.

 

21. Q:Which is the inheritance supported by PHP?

A: Is sure that PHP doesn’t support multiple inheritance, one single extended class depends forever on a base class . The class extension is made with “extends keyword”.

 

22.Q:How can the string be initialized best, with single or with double quotes?

A: The best thing to do is to use single quotes because this is not for variable substitution, We will use double quotes when the data inside the quotes needs variables substitution.

23.Q: What new and useful things have been implemented with version 5 of PHP?

A: a)a multitude of already made classes or interfaces under the name of Standard PHP Library (SPL).

b)already made exception classes that can be modified according to our needs through inheritance.

c)the PDO interface  for database systems.

d)the toolkit used for XML which is libxml2.

e)built in interfaces and classes and the most important is the iterator.

f)in OOP- now objects can be  passed by reference.

g)access modifiers

h)the use of prepare statements is permitted one with the ne mmysqli (improved mysql).

i)for developing more versatile  and high speed application SQLite appeared.

j)reverse engineering and object introspection now possible due to availability of reflection classes.

k)new Magic methods which initially have double underscore.

24.Q:What meaning has session_start()?

A: When a page in an application invoked the session_start()  method and a user finds it then for that user a session will be made by PHP to identify the user, a cookie is sent to the client by the name of PHPSESSID, this name can me modified in php.ini or with the session name() function.

 

25.Q:How can be Apache described?

A: Apache is a HTTP server on the internet that is one of the most common, this server is compatible with PHP and PERL languages. This server is a project that was developed and is developed by a group of international good will people that have put their effort together for a professional, reliable but free server.

 

 

 

 


online interview question with answer for php php ini interview question

2 Comments

  1. gaurav says:

    great

  2. Pankaj Singh says:

    This is one of the best collection of php interview question and answer so far I read online. No crap, just useful information. Very well presented. Check this link too its also useful for beginner as well as developer.
    http://www.mindstick.com/Interviewer/QuestionPage.aspx?topicid=11&topic=PHP

Leave a Reply