PHP Descriptive Question and Answer
Chapter 1-3
1.
What are the general language features of php?
Practicality: It requires minimum of
knowledge of programming.
Power: It has the ability to interface
with databases, from and create pages dynamically.
Possibility: It rarely bound to any
single implementation solution.
Price: It is free of charge.
- Who is the developer of php and when it is fasts developed?
Ans: Rasmus Lerdorf is the
developer of php and it is fasts developed in 1995.
- What are the four configuration Directive scopes?
Ans:PHP_INI_PERDIR, PHP_INI_USER,
PHP_INI_SYSTEM, PHP_INI_ALL.
- What are the configurations files of php and apache?
Ans:
PHP: php.ini.
Apache: apache.httpd.conf and .htaccess.
5.
Between echo () and print () functions which one is the
faster and why?
Between
echo () and print () there are technical difference. Echo () function is
a tad faster because it returns nothing, whereas print () will return 1 if the
statement is successfully output.
6.
What are type
casting and juggling?
Type casting: Converting values from
one data type to another is known as type casting.
Type Juggling: Automatic conversion is
known as type juggling.
7.
What is constant? How can you declare a constant?
A constant is a value that cannot be
modified throughout the execution of a program. Constants are particularly
useful when working with values that definitely will not require modification.
Constant are declared by using define
() function.
8.
Difference between get and post method?
get method is
used for submitting small amount of data. Data shows in the URL, so it is not
secure.
post method is
used for submitting small amount of data. Data does not show URL, so it is secure.
9.
What is super global variable? Write name of some
superglobal variable?
PHP
offers a number of useful predefined variables that are accessible from
anywhere within the
executing
script and provide us with a substantial amount of environment-specific
information.
Some
example: HTTP_HOST, HTTP_USER_AGENT, HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE.
10.
What is the difference between print and printf?
print statement output data passed to it.
Print(“I like PHP”);
The
printf() statement is ideal when we want to output a blend of static text and
dynamic information stored within one or several variables.
printf("Bar
inventory: %d bottles of tonic water.", 100);
11.
Write the name of 9 Superglobal Variables
I.
$_GET[ ],
II.
$_POST[ ],
III.
$_REQUEST[ ],
IV.
$_SERVER[ ],
V.
$_SESSION[ ],
VI.
$GLOBAL[ ],
VII.
$_COOKE[ ],
VIII.
$_FILES[ ],
IX.
$_ENV[ ]
12.
Which functions are used to add file in a script?
The functions are used to add file in a script
i) include()
ii) include_once()
iii) require()
iv) require_once()
13.
What is the difference between Session and Cookie?
The main difference between sessions and cookies is that
sessions are stored on the server, and cookies are stored on the user’s
computers in the text file format. Cookies cannot hold multiple variables, But
Session can hold multiple variables. We can set expiry for a cookie, The
session only remains active as long as the browser is open. Users do not have
access to the data you stored in Session, since it is stored in the server. Session
is mainly used for login/logout purpose while cookies using for user activity
tracking
14.
What are var_dump and print_r functions for?
Chapter 4: Functions
- What are passing arguments by reference and passing arguments by value?
When the value of the function argument is passed
by direct value or simple variable is called passing arguments by value and
when the value of the function argument is passed by reference variable is
called passing argument by reference.
Passing arguments by value: Means any changes made to those values within the scope of
the function are ignored outside of the function.
Passing arguments by reference: Means any changes made to those values within the scope of
the function are reflected outside of the function.
16.
What is recursive function?
Ans:
A
recursive function is a function that calls itself during its execution. This
enables the function to repeat itself several times, outputting the result and
the end of each iteration. Below is an example of a recursive function.
Function
Count (integer N)
if (N <= 0) return "Must be a Positive Integer";
if (N > 9) return "Counting Completed";
else return Count (N+1);
end function
if (N <= 0) return "Must be a Positive Integer";
if (N > 9) return "Counting Completed";
else return Count (N+1);
end function
- What is nesting function and recursive function?
Ans : -
We define a function
within another function it does not exist until the parent function is executed
is known nesting function.
Recursive functions, or functions that call themselves, offer
considerable practical value to the programmer and are used to divide an
otherwise complex problem into a simple case, reiterating that case until the
problem is resolved
Chapter 5: Arrays
- What Is an Array? How to output an array?
Ans : -
An array is traditionally defined as a group of items that share certain
characteristics.
Such as:-
$divisions = array (" Dhaka ",
"Khulna " , "Rajshahi" );
- Discuss the list function.
Ans : - The list() function is used to assign values to a list of
variables in one operation.
<?php
$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;
echo $a, $b, $c;
?>
$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;
echo $a, $b, $c;
?>
- Discuss array_push, array_pop, array_shift, array_unshift, array_pad.
Ans : -
array_push () — Push one or more elements onto the end of array. Such as: -
$
stack = array
("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
array_pop() pops and returns the last value of the
array.
array_shift() shifts the first value of the
array
off
and returns it. Such as : -
$states
= array("Ohio", "New York", "California",
"Texas"); $state = array_shift($states);
array_unshift() prepends passed elements to the front of the
array
.Such as : -
$queue = array("orange", "banana");
array_unshift($queue, "apple", "raspberry");
print_r($queue);
array_pad() returns a copy of the
array
padded to size specified by size
with value .
21. Discuss
in_array, array_values, array_search,
array_walk, count.
Ans: The in_array() function
searches an array for a specific value, returning TRUE if the value is found
and FALSE otherwise
$state
= "Ohio"; $states = array("California", "Hawaii",
"Ohio", "New York"); if(in_array($state, $states)) echo
"Not to worry, $state is smoke-free!";
array_values()
returns all the values from the
array
and
indexes the array numerically. Such as
:-
$population = array("Ohio" =>
"11,421,267", "Iowa" => "2,936,760");
print_r(array_values($population)); //
Array ( [0] => 11,421,267 [1] => 2,936,760 ) .
array_search () function searches an array for a specified value, returning its key if
located and FALSE otherwise . such as :-
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;.
array_walk() is not affected by the internal array pointer of
array
. array_walk()
will walk through the entire array regardless of pointer position
count — The count() function returns the total number of
values found in an array . Such as : -
$garden =
array("cabbage", "peppers", "turnips",
"carrots"); echo count($garden);
This returns the following. // 4
This returns the following. // 4
22.
What are the types of key of array?
Keys
can be numerical or associative. Numerical key use numeric value and
associative key use string value.
There are two types of key of array. It can be numerical and
associative.
Numerical: It
stores each array element with numeric index name.
Associative: It
contains characteristic element or string index name.
- Which functions are used to add and remove array elements?
There are four
functions used to add to and remove from array elements. These are-
- array_unshift():function adds element to the front of the array.
- array_push(): function adds element to the end of an array.
- array_shift(): function removes and returns the first item found in an array.
- array_pop():function removes and returns the last element from an array.
Chapter 6-7: Object Oriented PHP
- What is OOP?
Object-oriented programming is a style of
coding that allows developers to group similar tasks into classes. This helps
keep code following the tenet "don't repeat yourself" (DRY) and
easy-to-maintain.
- What are the three object-oriented features?
- What are the advantages of object-oriented programming?
- What are the five property scopes?
- What is property overloading?
Ans: Property
overloading continues to protect properties by forcing access and manipulation
through public methods, yet allowing the data to be accessed as if it were a
public property.
29.
What are class and object?
Class: Classes are intended to represent those
real-life items that coder like to manipulate within an application.
Object: An instance of class is called object. Such
as $employee = new Employee();
Classes are intended to represent those real-life
items that coder like to manipulate within an application.
- What is property overloading?
Property overloading continues to
protect properties by forces access and manipulation through public methods.
Property overloading continues to
protect properties by forcing access and manipulation through public methods,
yet allowing the data to be accessed as if it were a public property.
- What are constructor and destructor?
Ans. Constructor: A constructor is defined as a
block of codes that automatically executes at the time of objects
instantiation.
Destructors: When the script is complete, PHP
will destroy any object that resides in memory. Destructor modifies the object
destruction process. If less volatile data is created as a result of the
instantiation and should be destroyed at the time of object destruction. We
will need to create a custom destructor.
- What is object cloning?
Ans. Clone: Object cloning
means creating a copy of an object with fully replicated properties
$classA = new CloneableClass();
$classB = clone $classA;
- What type of inheritance that PHP supports?
Inheritance is one of the popularly
used Object Oriented Programming feature to have shared properties and
functions between related classes. PHP generally supports single type of
inheritance.
- What are the abstract class and interface?
Abstract class: An abstract class is class that
really isn’t supposed to ever be instantiated but instead serves as a base
class to be inherited by other classes.
Interface: An interface defines a general specification
for implementing a particular service, declaring the required functions and
constants without specifying exactly how it must be implemented.
Chapter 8: Error and Exception Handling
- Define exceptions?
In programming,
often involves unforeseen happenings that disrupt the flow of events. These unexpected
happenings are known as exceptions. An Exception is 'thrown', when an
exceptional event happens.
Chapter 9: Strings and Regular Expressions
- What is regular expression?
Regular
expressions provide the foundation for describing or matching data according to
defined syntax rules. A regular expression is nothing more than a pattern of
characters itself, matched against a certain parcel of text.
- What are the two regular expression syntaxes?
Ans: There are two regular
expression syntaxes in php. These are
1. POSIX syntax and
2. Perl syntax.
38.
What is the functionality of the function strstr and
stristr?
strstr(): It returns the remainder of a string beginning
with the first occurrence of a predefined string.
stristr(): same as strstr except the search of for the
pattern is case insensitive.
39.
What is the difference between ereg_replace() and
eregi_replace()?
ereg_replace(): it is used to find and replace a pattern
with a replacement string.
eregi_replace(): same as ereg_replace() except the search
of for the pattern is case insensitive.
40.
What are the different functions in sorting an array? Discuss
them?
sort(): sort
array in ascending order.
rsort():sort
array in descending order.
asort() : Sort
array in ascending order with key/value.
arsort(): reverse
of assort.
natsort (): sorting
the in order we expect.
natcasesort(): case
insensitive natsort.
ksort(): sorts an
array by its keys.
krsort(): reverse
of ksort
Usort(): sorting
an array by using user defined comparison algorithm
Chapter 10: Working with the File and Operating system
41.
What are the functions unlink and unset?
Ans: unlink(): delete/remove a file.
unset(): destroy any specified
variable or array from system.
42.
Why
php fopen/fclose is use ?
Ans: fopen(): Opens file or URL
fclose(): Close file or URL
43.
Difference between w, r, a and a+ mode of file?
w
mode: Write on a new file or write on an existing file after
deleting content.
r mode:
Read content of an existing file.
A mode:
Write on a new file or append on an existing file.
a+
mode: Write on a new file or append on an existing file and read from
the file.
44.
How many ways you can read file?
We can read file using the following mode and
methods:-file(), file_get_contents(), fgetcsv(), fgetss(), fgetc(), fread(), readfile(),
fscnaf().
Mode-R,r+,w+,a+,x+.
45.
How many way you can write into file?
We can write into a file using the
following mode and Methods:
Methods-fwrite() with fopen,
file_put_contants().
Mode-r+,W,w+,A,a+,X,x+
46.
Why substr() is used?
The
substr() function used to returns the
part of a string located between a predefined starting
offset
and length positions.
<?php
echo substr("Hello World!"6,5);
?>
47.
Why explode() is used?
The explode()
function splits a string into a series of substrings, with each string boundary
determined by a specific separator and convert a string to array.
$pizza =
"piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
48.
Difference between strpos() and strrpos()?
The strpos() function finds the position of the first
case-sensitive occurrence of a substring in a string whereas strrpos ()
function finds the last occurrence of a string returning the numerical
position.
49.
Difference between array_merge() and array_slice()?
The array_merge () function merges array together returning
a single, unified array whereas the array_slice () function returns a section
of an array based on a starting and ending offset value.
50.
What should we do to be able to export data into an Excel
file?
The most common and used way is to get data into a format
supported by Excel. For example, it is possible to write a .csv file, to choose
for example comma as separator between fields and then to open the file with
Excel.
Chapter 11: PEAR
51.
What are the benefits of using PEAR? Or, what is PEAR? What
is the benefit of using pear?
Answer:
a)
It's most effective for finding and
reusing great PHP code.
b)
Standard development guidelines are
assured.
c)
It offers more than 550 packages categorized
under 37 different topics.
Chapter 13: Working with HTML Forms
52.
What is the functionality of the function htmlentities and
strip_tags?
53.
What is Sanitizing User Input in php? Which function we use usually used for
Sanitizing User Input?
Chapter 14: Authenticating your Users
54.
What is HTTP Authentication?
HTTP is able to use several authentication
mechanisms to control access to specific websites and applications. There are three
authentication systems available
·
Hard-coded
authentication
·
File-based
authentication
·
Database-based
authentication
55.
What are the PHP’s authentication variables?
Ans: PHP uses two
predefined variables to authenticate a user and those are
$_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']. These variables store
the username and password values, respectively.
56.
What is the purpose of header() function?
The header()
function sends a raw HTTP header to a client browser. Remember that this
function must be called before sending the actual output. For example, You do
not print any HTML element before using this function. It is most frequently
used to redirect request to get other file.
Example:
The following
code can be used for it,
header("Location:index.php");
57.
What are the types of PHP authentication?
There are three authentication systems available
1. Hard-coded authentication: The simplest way to restrict resource access
is by hard-coding the username and password directly into the script.
2. File-based authentication
3. Database-based authentication
Chapter 15: Handling File Uploads
58.
What are the functions used for file upload?
Ans: PHP’s
built-in file-upload functions: is_upload_file() and move_upload_file().
59.
Which form attribute is used for file upload?
Ans: enctype="multipart/form-data"
60.
Which is the directive determine the maximum size of the
uploaded file?
61.
What are the functions used for file upload?
62.
What does define by UPLOAD_ERR_INI_SIZE and
UPLOAD_ERR_FORM_SIZE error message?
63.
Discuss five predefined subscript of of $_FILES super
global variable?
or
What are the five items of the $_FILES Array?
Five predefined subscripts of
$_FILES super global variable are discussed below:
1.$_FILES['upload
name']['name']: The name of the file as uploaded from the client to the
server.
2.$_FILES['upload
name']['type']:The MIME type of the uploaded file. Whether this variable
is assigned depends on the browser
capabilities.
3.$_FILES['upload
name']['size']: The byte size of the uploaded file.
4.$_FILES['upload
name']['tmp_name']: Once uploaded, the file will be assigned a temporary
name before it is moved to its final location.
5.$_FILES['upload
name']['error']: An upload status code.Despite the name, this variable
will be populated even in the case of
success.
64.
What are the five items of the $_FILES Array?
65.
Write down the function of file upload?
66.
Uploaded error message
1)
The error code can be found in the error
segment of the file array that is created during the file upload by PHP. The error might be found in $_FILES['userfile']['error'].
2)
UPLOAD_ERR_OK
3)
Value: 0; There is no error, the file uploaded
with success.
4)
UPLOAD_ERR_INI_SIZE
6)
UPLOAD_ERR_FORM_SIZE
7)
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE
directive that was specified in the HTML form.
8) UPLOAD_ERR_PARTIAL
9)
Value: 3; The uploaded file was only partially
uploaded.
10)
UPLOAD_ERR_NO_FILE
11)
Value: 4; No file was uploaded.
12)
UPLOAD_ERR_NO_TMP_DIR
13)
Value: 6; Missing a temporary folder.
14)
UPLOAD_ERR_CANT_WRITE
15)
Value: 7; Failed to write file to disk.
16)
UPLOAD_ERR_EXTENSION
17)
Value: 8; A PHP extension stopped the file
upload.
67.
upload_tmp_dir
an uploaded file must be successfully transferred to the
server before subsequent processing on that file can begin, a staging area of
sorts must be designated for such files where they can be temporarily placed until they are moved to
their final location. This staging location is specified using the upload_tmp_dir
directive.
Chapter 16: Networking
68.
What is DNS?
Ans: DNS stands for the domain name
system what allows you to use domain names in place if the corresponding IP
address.
69.
Mention five Internet services?
1. HTTP - Hyper Text Transfer Protocol
2. FTP - File Transfer Protocol
3. POP3 - Post Office Protocol
4. IMAP - Internet Message Access Protocol
5.
SSH - Secure SHell
70.
Explain the parameters of PHP’s mail function.
71.
How to check the existence of DNS records ?
Ans: we can check the existence of
DNS records using the checkdnsrr() function.
72.
What are the four attribute of dns_get_record() ?
Ans: The four attributes of
dns_get_record are : host, class, type,
ttl.
73.
How to retrieve DNS resource records ?
Ans: we can retrieve DNS resource
records using the dns_get_record() function.
74.
How to retrieve the service port Number?
Ans: The getservbyname() function
returns the port number of a specified service.
Prototype:
int getservbyname(string service,
string protocol)
Example:
<?php
echo "HTTP's default port number is:
".getservbyname("http","tcp");
?>
- Mention five configuration directives of PHP’s mail function ?
Ans.: There are five configuration
directives as below: SMTP, send_from, sendmail_path, smtp_port, mail.force_extra_parameters.
76.
How to send E-mail using PHP script ?
Ans: Email can be sent through a
PHP script in amazingly easy fashion, using the mail() function.
Chapter 18: Session Handlers
77.
Why HTTP is called stateless protocol?
PHP is called stateless protocol, meaning
that each request is processed without any knowledge of prior or future
requests.
78.
How many ways session handling can be done?
Ans: Session
handling can be done with two ways:
a. Cookies: When
a user visits a web site, the server stores information about the user in a cookie
and sends it to the browser, which saves it.
b. URL rewriting:
SID is propagates automatically whenever the user clicks any local link.
References: http://www.sitepoint.com/php-sessions/
79.
What is Session-Handling?
Session handling is one
of the key things which most of web applications and projects need.
Suppose building one
E-commerce site, to allow anyone to buy the product application must ask them
to log-in with their user name and until they log out your system must track
the user in every step. As HTTP is state
less protocol, and when you refresh the page, it lost everything, we need to
remember users states.
80.
What are encoding and decoding?
session_encode() offers a convenient
method for manually encoding all session variables into a single string. Its
prototype follows: string session_encode().
Encoded session data can be decoded with
session_decoded ().
Its prototype follows: boolean
session_decode(string session_data).
No comments:
Post a Comment