Showing posts with label PHP Interview questions. Show all posts
Showing posts with label PHP Interview questions. Show all posts

Friday, March 25, 2011

PHP Interview Question Part 5

1. Name and explain five of the PHP error constants?
  • E_ERROR: -This error is displayed when there is fatal error which halts the execution of the script immediately.
  • E_WARNING: -This warns the programmer about the error but the execution of the script is not stopped.
  • E_PARSE: -These errors occur during compile time and these errors should only be generated by the parser.
  • E_USER_WARNING: -This warning error is generated by the user and is non fatal. This is set by the programmer using trigger_error().
  • E_COMPILE_WARNING: -this error is generated by the Zend scripting engine. This is a compile time non fatal error.

PHP Interview Question Part 4

1. Describe about the security vulnerability of PHP?
According to the information obtained from the National vulnerability database, PHP has more than quarter of the software vulnerabilities discovered in 2008. Out of 33.33% software and scripts vulnerability PHP amounts to almost quarter of them. Register_globals a feature present in PHP is responsible for most of these vulnerabilities and now it is deprecated by PHP. Most of these security vulnerabilities occur due to poor programming techniques.
 
2. Explain about the data types in PHP?
PHP stores information numerical in a platform dependent range. Unsigned integers can be easily converted to signed integers. Decimal, octal, and hexadecimal notations can be easily assigned to integers. Floating point notation and two forms of scientific notation can be easily assigned to Real numbers. Zero is considered as false and all non zero numbers are considered as true.

3. What is a PHP accelerator?
PHP accelerator increases the speed of applications written in PHP. This boost of performance can be around 2-10 times. PHP accelerator increases the speed of the applications by decreasing parsing each and every time a PHP application runs. It depends upon factors such as time taken for execution of the PHP script and the actual percentage of the source code requested.
 
4. Explain about PHP cookies?
A Cookie is placed on the user desktop which uniquely identifies the user and every time a user views the webpage the same cookie is retrieved. With PHP a programmer can create and retrieve information simultaneously. The setcookie() function is used to create a cookie and PHP $_COOKIE variable helps the programmer to retrieve the cookie stored on the users computer. These both functions can function simultaneously.

5. Explain about Functions in PHP?
PHP has a large pool of functions and a huge number of them can be created by extensions. These functions can be defined at runtime by defining them inside the code. These functions have to be defined inside the parenthesis except for a class constructor function where there is no argument. Functions can be called or referenced by specifying their name.
 
6. Explain about objects in PHP?
In previous versions of PHP, object was fully copied before assigning a variable to a method. This problem was solved in new versions of PHP by the handle function. Many of the features present in PHP 5 are adopted from C++. Some of the features which are incorporated are restricted classes such as private and public, abstract and final classes, abstract and final methods, constructors and destructors with exception handling borrowed from C++.

7. Describe about PHP error and logging information?
Error handling function allows the user to detect the error and do necessary changes which paved the way for the error.
Logging functions pave the way for users to use log applications and send messages to system logs, email or for other specific purpose.
PHP has efficient error and logging constants to its credit. Some of them are E_ERROR, E_NOTICE, E_ALL, E_STRICT, etc.
 
 

PHP Interview Question Part 3

1. Explain about switch statement in PHP?
Switch statement is executed line by line. PHP executes the statement only when the case statement matches the value of the switch expression. It does execute the statement until the end of the block till it finds the break statement. When the expression and statement matches themselves the code is executed.
 
2. Define about declare construct?
Declare construct allows you to define execution directives for a block set of code. This actually describes the way the code should perform. These declare construct can be set in such a manner that all the code is affected. The way the code performs can be set by the directive part which directly leads the code to follow.

3. Explain about looping in PHP?
Looping is used to run the same script many number of times. Following statements are used in PHP for looping while, do...while, for each, and for statement.
 
4. Explain about require and include function?
Include function collects all the text in a defined specific file and copies the text information to the file which has the include function in it
Require function is similar to the include function except that it handles the error system in a different manner. Require function displays a fatal error and stops the execution of the script while the include function still executes the script.

5. What is the alternative structure for control structures?
The basic control structures are if, for, while, do while, for each and switch. If you are planning to use alternative structures then the closing braces should be changed to endif, endfor, endwhile, endswitch, and endforeach. Similarly the opening brace of the alternative syntax should be changed to (:) or colon. The alternative structure is applicable to else and elseif also.

6. What are the different filter functions used to filter a variable?
  • Filter_var()
  • Filter_var_array()
  • Filter_input
  • Filter_input_array
7. Explain about PHP filter and why it should be used?
A PHP filter validates, filters according to the predefined statements from the programmer. It is very important for every programmer to validate user defines information as it can potential harm; PHP eliminated this risk by using PHP filter extension. This forms a good security practice for programmers.
 

Friday, March 18, 2011

PHP Interview Question Part 2


1. What is the difference between echo and print statement?
There is a slight difference between print and echo which would depend on how you
want to use the outcome. Using the print method can return a true/false value. This may
be helpful during a script execution of somesort. Echo does not return a value, but has
been considered as a faster executed command. All this can get into a rather
complicated discussion, so for now, you can just use whichever one you prefer.

2.How to make a download page in own site, which i can know that how many file has
been loaded by particular user or particular ipaddress?

We can use hyperlink having URL where file are kept. and we only allow regisetered
user to download. from session of user we can get the user detail

3. What is the difference between mysql_connect and mysql_pconnect?
 mysql_pconnect establishes a persistent connection. If you don't need one (such as a
website that is mostly HTML files or PHP files that don't call the db) then you don't
need to use it. mysql_connect establishes a connection for the duration of the script
that access the db. Once the script has finished executing it closes the connection. The
Templateshut.com
only time you need to close the connection manually is if you jump out of the script for
any reason.
If you do use mysql_pconnect. You only need to call it once for the session. That's the
beauty of it. It will hold open a connection to the db that you can use over and over
again simply by calling the resource ID whenever you need to interact with the db.

4. How can I get IP Address?
We can use SERVER var $_SERVER['SERVER_ADDR'] and getenv("REMOTE_ADDR")
functions to get the IP address.

5. How we know the browser properties?
get_browser() attempts to determine the capabilities of the user's browser. This is done
by looking up the browser's information in the browscap.ini file.
echo $_SERVER['HTTP_USER_AGENT'] . "

6. What is the difference between require_once(), require(), include().
Difference between require() and require_once(): require() includes and evaluates a
specific file, while require_once() does that only if it has not been included before (on
the same page). So, require_once() is recommended to use when you want to include a
file where you have a lot of functions for example. This way you make sure you don't
include the file more times and you will not get the "function re-declared" error.
Difference between require() and include() is that require() produces a FATAL ERROR
if the file you want to include is not found, while include() only produces a WARNING.
There is also include_once() which is the same as include(), but the difference between
them is the same as the difference between require() and require_once().

7. What is CAPTCHA?
CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and
Humans Apart. To prevent spammers from using bots to automatically fill out forms,
CAPTCHA programmers will generate an image containing distorted images of a string
of numbers and letters. Computers cannot determine what the numbers and letters are
from the image but humans have great pattern recognition abilities and will be able to
fairly accurately determine the string of numbers and letters. By entering the numbers
and letters from the image in the validation field, the application can be fairly assured
that there is a human client using it.