PHP Interview Questions and Answers for freshers and experienced – 02
|Questions : 21||How can we encrypt the username and password using PHP?|
|Answers : 21||The functions in this section perform encryption and decryption, and
compression and uncompression:
|Questions : 22||What are the features and advantages of object-oriented
|Answers : 22||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
|Questions : 23||What are the differences between procedure-oriented languages and
|Answers : 23||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 .
|Questions : 24||What is the use of friend function?|
|Answers : 24||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.
|Questions : 25||What are the differences between public, private, protected,
static, transient, final and volatile?
|Answer : 25||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
|Questions : 26||What are the different types of errors in PHP?|
|Answer : 26||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.
|Questions : 27||What is the functionality of the function strstr and stristr?|
|Answers : 27||strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to the end of string.
$email= ‘sonial[email protected]’;
$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
|Questions : 28||How can we submit a form without a submit button?|
|Answer : 28||Java script submit() function is used for submit form without submit button
on click call document.formname.submit()
|Questions : 29||How can we convert asp pages to PHP pages?|
|Answer : 29||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./
|Questions : 30||What is the functionality of the function htmlentities?|
|Answer : 30||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.
|Questions : 31||How can we get second of the current time using date function?
|Answer : 31||$second = date(“s”);|
|Questions : 32||How can we convert the time zones using PHP?|
|Answer : 32||For convert the time zones using PHP we have to first set time zone
By using PHP function date_default_timezone_set()
If we want to set time zone of ‘Europe/London’ we have to call this funtion as
so Now generate the timestamp for that particular timezone, on Sept 1st, 2012 at 8 am
$pcds = mktime(8, 0, 0, 9, 1, 2012);
Now set the other timezone like US/Eastern
date(DATE_RFC1123, $pcds) date(DATE_RFC1123, $pcds)
Output the date in a standard format (RFC1123)
|Questions : 33||What is meant by urlencode and urldocode?|
|Answer : 33||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.
|Questions : 34||What is the difference between the functions unlink and unset?
|Answer : 34||unlink() deletes the given file from the file system.
unset() makes a variable undefined.
|Questions : 35||How can we register the variables into a session?|
|Answer : 35||$_SESSION[‘name’] = “sonia”;|
|Questions : 36||How can we get the properties (size, type, width, height) of an
image using PHP image functions?
|Answer : 36||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
|Questions : 37||How can we get the browser properties using PHP?|
|Answer : 37||By using
|Questions : 38||What is the maximum size of a file that can be uploaded using PHP
and how can we change this?
|Answer : 38||By default the maximum size is 2MB. and we can change the following
setup at php.iniupload_max_filesize = 2M
|Questions : 39||How can we increase the execution time of a PHP script?|
|Answer : 39||by changing the following setup at php.inimax_execution_time = 30
; Maximum execution time of each script, in seconds
|Questions : 40||How can we take a backup of a MySQL table and how can we restore
|Answer : 40||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!