PHP Interview Questions and Answers – Part 2
21. How can we encrypt the username and password using PHP?
The functions in this section perform encryption and decryption, and
compression and uncompression:
|SHA() or SHA1()||Not available|
22 What are the features and advantages of object-oriented programming?
One of the main advantages of OO programming is its ease of
modification; objects can easily be modified and added to a system there
by reducing maintenance costs. OO programming is also considered to be
better at modeling the real world than is procedural programming. It
allows for more complicated and flexible interactions. OO systems are
also easier for non-technical personnel to understand and easier for
them to participate in the maintenance and enhancement of a system
because it appeals to natural human cognition patterns.
For some systems, an OO approach can speed development time since many
objects are standard across systems and can be reused. Components that
manage dates, shipping, shopping carts, etc. can be purchased and easily
modified for a specific system
23 What are the differences between procedure-oriented languages and object-oriented languages?
There are lot of difference between procedure language and object oriented like below
1>Procedure language easy for new developer but complex to understand whole software as compare to object oriented model
2>In Procedure language it is difficult to use design pattern mvc , Singleton pattern etc but in OOP you we able to develop design pattern
3>IN OOP language we able to ree use code like Inheritance ,polymorphism etc but this type of thing not available in procedure language on that our Fonda use COPY and PASTE .
24 What is the use of friend function?
Sometimes a function is best shared among a number of different
classes. Such functions can be declared either as member functions of
one class or as global functions. In either case they can be set to be
friends of other classes, by using a friend specifier in the class that
is admitting them. Such functions can use all attributes of the class
which names them as a friend, as if they were themselves members of that
A friend declaration is essentially a prototype for a member function,
but instead of requiring an implementation with the name of that class
attached by the double colon syntax, a global function or member
function of another class provides the match.
25 What are the differences between public, private, protected, static, transient, final and volatile?
Public: Public declared items can be accessed everywhere.
Protected: Protected limits access to inherited and parent
classes (and to the class that defines the item).
Private: Private limits visibility only to the class that defines
Static: A static variable exists only in a local function scope,
but it does not lose its value when program execution leaves this scope.
Final: Final keyword prevents child classes from overriding a
method by prefixing the definition with final. If the class itself is
being defined final then it cannot be extended.
transient: A transient variable is a variable that may not
volatile: a variable that might be concurrently modified by multiple
threads should be declared volatile. Variables declared to be volatile
will not be optimized by the compiler because their value can change at
26 What are the different types of errors in PHP?
Three are three types of errors:
1. Notices: These are trivial,non-critical errors that PHP encounters while executing a script â€“ for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all â€“ although, as you will see, you can change this default behavior.
2. Warnings: These are more serious errors â€“ for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors â€“ for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.
27 What is the functionality of the function strstr and stristr?
strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to the end of string.
$domain = strstr($email, ‘@’);
echo $domain; // prints @gmail.com
here @ is the needle
stristr is case-insensitive means able not able to diffrenciate between a and A
28 How can we submit a form without a submit button?
Java script submit() function is used for submit form without submit button on click call document.formname.submit()
29 How can we convert asp pages to PHP pages?
There are lots of tools available for asp to PHP conversion. you can search Google for that. the best one is available athttp://asp2php.naken.cc./
30 What is the functionality of the function htmlentities?
Convert all applicable characters to HTML entities
This function is identical to htmlspecialchars() in all ways, except
with htmlentities(), all characters which have HTML character entity
equivalents are translated into these entities.
31 How can we get second of the current time using date function?
$second = date(“s”);
32 How can we convert the time zones using PHP?
By using date_default_timezone_get and
date_default_timezone_set function on PHP 5.1.0
// Discover what 8am in Tokyo relates to on the East Coast of the US
// Set the default timezone to Tokyo time:
// Now generate the timestamp for that particular timezone, on Jan 1st, 2000
$stamp = mktime(8, 0, 0, 1, 1, 2000);
// Now set the timezone back to US/Eastern
// Output the date in a standard format (RFC1123), this will print:
// Fri, 31 Dec 1999 18:00:00 EST
echo ‘<p>’, date(DATE_RFC1123, $stamp) ,'</p>’;?>
33 What is meant by urlencode and urldocode?
URLencode returns a string in which all non-alphanumeric characters
except -_. have been replaced with a percent (%)
sign followed by two hex digits and spaces encoded as plus (+)
signs. It is encoded the same way that the posted data from a WWW form
is encoded, that is the same way as in
application/x-www-form-urlencoded media type.
urldecode decodes any %##
encoding in the given string.
34 What is the difference between the functions unlink and unset?
unlink() deletes the given file from the file system.
unset() makes a variable undefined.
35 How can we register the variables into a session?
$_SESSION[‘name’] = “tut2learn”;
36 How can we get the properties (size, type, width, height) of an image using PHP image functions?
To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function t
37 How can we get the browser properties using PHP?
38 What is the maximum size of a file that can be uploaded using PHP and how can we change this?
By default the maximum size is 2MB. and we can change the following
setup at php.iniupload_max_filesize = 2M
39 How can we increase the execution time of a PHP script?
by changing the following setup at php.inimax_execution_time = 30
; Maximum execution time of each script, in seconds
40 How can we take a backup of a MySQL table and how can we restore it. ?
To backup: BACKUP TABLE tbl_name[,tbl_nameâ€¦] TO
RESTORE TABLE tbl_name[,tbl_nameâ€¦] FROM ‘/path/to/backup/directory’mysqldump: Dumping Table Structure and DataUtility to dump a database or a collection of database for backup or
for transferring the data to another SQL server (not necessarily a MySQL
server). The dump will contain SQL statements to create the table and/or
populate the table.
Don’t write table creation information (the CREATE TABLE statement).
Don’t write any row information for the table. This is very useful if
you just want to get a dump of the structure for a table!
|SHA() or SHA1()||Not available|