php Interview Questions
Who is the father of PHP ?
Rasmus Lerdorf is known as the father of PHP.
What is the difference between $name and $$name?
$name is variable where as $$name is reference variable like $name=sonia and $$name=singh so $sonia value is singh.
What are the method available in form submitting?
GET and POST
How can we get the browser properties using PHP?
What Is a Session?
A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests. Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.
How can we register the variables into a session?
How many ways we can pass the variable through the navigation between the pages?
Register the variable into the session
Pass the variable as a cookie
Pass the variable as part of the URL
How can we know the total number of elements of Array?
How can we create a database using php?
What is the functionality of the function strstr and stristr?
strstr() returns part of a given string from the first occurrence of a given substring to the end of the string.
For example:strstr(“email@example.com”,”@”) will return “@example.com”.
stristr() is idential to strstr() except that it is case insensitive.
What are encryption functions in PHP?
How to store the uploaded file to the final location?
move_uploaded_file( string filename, string destination)
The mysql_error() message will tell us what was wrong with our query, similar to the message we would receive at the MySQL console.
What is Constructors and Destructors?
CONSTRUCTOR : PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.
Explain the visibility of the property or method.
The visibility of a property or method must be defined by prefixing the declaration with the keywords public, protected or private.
Class members declared public can be accessed everywhere.
Members declared protected can be accessed only within the class itself and by inherited and parent classes.
Members declared as private may only be accessed by the class that defines the member.
What are the differences between Get and post methods.
There are some defference between GET and POST method
1. GET Method have some limit like only 2Kb data able to send for request
But in POST method unlimited data can we send
2. when we use GET method requested data show in url but
Not in POST method so POST method is good for send sensetive request
What are the differences between require and include?
Both include and require used to include a file but when included file not found
Include send Warning where as Require send Fatal Error
What is use of header() function in php ?
The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen.
List out the predefined classes in PHP?
What type of inheritance that PHP supports?
In PHP an extended class is always dependent on a single base class,that is, multiple inheritance is not supported. Classes are extended using the keyword ‘extends’.
How can we encrypt the username and password using php?
You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD(“Password”);
We can encode data using base64_encode($string) and can decode using base64_decode($string);
What is the difference between explode and split?
Split function splits string into array by regular expression. Explode splits a string into array by string.
For Example:explode(” and”, “India and Pakistan and Srilanka”);
split(” :”, “India : Pakistan : Srilanka”);
Both of these functions will return an array that contains India, Pakistan, and Srilanka.
How do you define a constant?
Constants in PHP are defined using define() directive, like define(“MYCONSTANT”, 100);
How do you pass a variable by value in PHP?
Just like in C++, put an ampersand in front of it, like $a = &$b;
What does a special set of tags do in PHP?
The output is displayed directly to the browser.
How do you call a constructor for a parent class?
What’s the special meaning of __sleep and __wakeup?
__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.
What is the difference between the functions unlink and unset?
unlink() deletes the given file from the file system.
unset() makes a variable undefined.
How many ways can we get the value of current session id?
session_id() returns the session id for the current session.
What are default session time and path?
default session time in PHP is 1440 seconds or 24 minutes
Default session save path id temporary folder /tmp
for image work which library?
we will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.
How can we get second of the current time using date function?
$second = date(“s”);
What are the Formatting and Printing Strings available in PHP?
printf()- Displays a formatted string
sprintf()-Saves a formatted string in a variable
fprintf() -Prints a formatted string to a file
number_format()-Formats numbers as strings
How can we find the number of rows in a result set using PHP?
$result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;