You are on page 1of 8

NOTE: For Final practical-viva firstly go through all the 15 practical file

questions. You have to study in detail all the library functions used in those 15
practical’s .

After that go through these viva questions. These will also help you in final
theory paper.

Q1-What is PHP?
PHP stands for Hypertext Pre-processor. It is an open source server-side scripting language which is widely
used for web development. It supports many databases like MySQL, Oracle, Sybase, Solid, PostgreSQL, generic
ODBC etc.

Q2-What are the different types of PHP variables?

There are 8 data types in PHP which are used to construct the variables:

1. Integers − are whole numbers, without a decimal point, like 4195.


2. Doubles − are floating-point numbers, like 3.14159 or 49.1.
3. Booleans − have only two possible values either true or false.
4. NULL − is a special type that only has one value: NULL.
5. Strings − are sequences of characters, like ‘PHP supports string operations.’
6. Arrays − are named and indexed collections of other values.
7. Objects − are instances of programmer-defined classes, which can package up both other kinds of
values and functions that are specific to the class.
8. Resources − are special variables that hold references to resources external to PHP.

Q3- What are the rules for naming a PHP variable?


The following rules are needed to be followed while naming a PHP variable:

 Variable names must begin with a letter or underscore character.


 A variable name can consist of numbers, letters, underscores but you cannot use characters like + , – ,
% , ( , ) . & , etc.

Q4- How do you define a constant in PHP?


To define a constant you have to use define() function and to retrieve the value of a constant, you have to
simply specifying its name.If you have defined a constant, it can never be changed or undefined. There is
no need to have a constant with a $. A valid constant name starts with a letter or underscore.
Q5- What is the purpose of constant () function?
The constant () function will return the value of the constant. This is useful when you want to retrieve value of
a constant, but you do not know its name, i.e., it is stored in a variable or returned by a function

Q6- What are constructor and destructor in PHP?


PHP constructor and destructor are special type functions which are automatically called when a PHP class
object is created and destroyed. The constructor is the most useful of the two because it allows you to send
parameters along when creating a new object, which can then be used to initialize variables on the object.

Q7-What are include() and require() functions?


The Include() function is used to put data of one PHP file into another PHP file. If errors occur then the
include() function produces a warning but does not stop the execution of the script and it will continue to
execute. If the function require() cannot access the file then it ends with a fatal error. However,
the include() function gives a warning, and the PHP script continues to execute.

Q8-What is GET and POST method in PHP?


The GET method sends the encoded user information appended to the page request. The page and the encoded
information are separated by the ? character.

The POST method transfers information via HTTP headers. The information is encoded as described in case of
GET method and put into a header called QUERY_STRING.

What is the difference between GET and POST method?

GET POST
 The GET method is restricted to send upto 1024  The POST method does not have any restriction
characters only. on data size to be sent.

 GET can’t be used to send binary data, like  The POST method can be used to send ASCII
images or word documents, to the server. as well as binary data.

 The data sent by POST method goes through


 The data sent by GET method can be accessed
HTTP header so security depends on HTTP
using QUERY_STRING environment variable.
protocol.

 The PHP provides $_GET associative array to  The PHP provides $_POST associative array to
access all the sent information using GET access all the sent information using POST
method. method.

Q9-What are PHP Magic Methods/Functions?


In PHP all functions starting with _ _ names are magical functions/methods. These methods, identified by a two
underscore prefix (__), function as interceptors that are automatically called when certain conditions are
met. PHP provides a number of ‘magic‘ methods that allow you to do some pretty neat tricks in object oriented
programming.

Here are list of Magic Functions available in PHP

__destruct() __sleep()
__construct() __wakeup()
__call() __toString()
__get() __invoke()
__set() __set_state()
__isset() __clone()
__unset() __debugInfo()

Q-What was the old name of PHP?

The old name of PHP was Personal Home Page.

Q-What is the name of scripting engine in PHP?

The scripting engine that powers PHP is called Zend Engine 2.

Q-What is "echo" in PHP?

PHP echo output one or more string. It is a language construct not a function. So the use of parentheses is not
required. But if you want to pass more than one parameter to echo, the use of parentheses is required.

Q-What is the difference between "echo" and "print" in PHP?

Echo can output one or more string but print can only output one string and always returns 1.

Echo is faster than print because it does not return any value.

Q- $ and $$ Variables

The $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float,
etc.

The $$var (double dollar) is a reference variable that stores the value of the $variable inside it.

To understand the difference better, let's see some examples.

Q How is the comparison of objects done in PHP?


We use the operator ‘==’ to test is two objects are instanced from the same class and have
same attributes and equal values. We can test if two objects are referring to the same
instance of the same class by the use of the identity operator ‘===’.

Q 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 a separator
between fields and then to open the file with Excel.

Q-How can we connect to a MySQL database from a PHP script?


To be able to connect to a MySQL database, we must use mysqli_connect() function as
follows:

<!--?php $database = mysqli_connect("HOST", "USER_NAME", "PASSWORD");


mysqli_select_db($database,"DATABASE_NAME"); ?-->

Q-What does the unlink() function mean?


The unlink() function is dedicated for file system handling. It simply
deletes the file given as entry.
Q-What does the unset() function mean?
The unset() function is dedicated for variable management. It will make a variable
undefined.

Q-How is a constant defined in a PHP script?


The define() directive lets us defining a constant as follows:

define ("ACONSTANT", 123);

Q-How can you pass a variable by reference?


To be able to pass a variable by reference, we use an ampersand in front of it, as follows
$var1 = &$var2

Q-What is the function func_num_args() used for?


The function func_num_args() is used to give the number of parameters passed into a
function.

Q-What does $_SERVER mean?


$_SERVER is an array including information created by the web server such as paths,
headers, and script locations.

Q-What does the array operator ‘===’ means?


($a === $b) === Operator: This operator is used to check the given values and its data
type are equal or not. If yes, then it returns true, otherwise it returns false.
Q-What is the differences between $a != $b and $a !== $b?
!= means inequality (TRUE if $a is not equal to $b) and !== means non-identity (TRUE if
$a is not identical to $b).

That means $a != $b - Check if the value of $a is not equal to $b. However, with $a !==
$b, the value of $a is matched with $b, and also the 'data Type' which must be same.

Q) What is the meaning of a Persistent Cookie?

A persistent cookie is permanently stored in a cookie file on the browser’s computer. By


default, cookies are temporary and are erased if we close the browser.

Q) What are the different types of Array in PHP?


There are 3 types of Arrays in PHP:

1. Indexed Array – An array with a numeric index is known as the indexed array. Values are stored and
accessed in linear fashion.
2. Associative Array – An array with strings as index is known as the associative array. This stores
element values in association with key values rather than in a strict linear index order.
3. Multidimensional Array – An array containing one or more arrays is known as multidimensional
array. The values are accessed using multiple indices.

Q-What is the difference between “echo” and “print” in PHP?

 PHP echo output one or more string. It is a language construct not a function. So use of parentheses is
not required. But if you want to pass more than one parameter to echo, use of parentheses is required.
Whereas, PHP print output a string. It is a language construct not a function. So use of parentheses is
not required with the argument list. Unlike echo, it always returns 1.
 Echo can output one or more string but print can only output one string and always returns 1.
 Echo is faster than print because it does not return any value

Q-PHP Operators

PHP Operator is a symbol i.e used to perform operations on operands. In simple words, operators are used to
perform operations on variables or values

 Arithmetic operators
 Assignment operators
 Comparison operators
 Increment/Decrement operators
 Logical operators
 String operators
 Array operators
 Conditional assignment operators

*you have to give 2-3 examples of these operators also.


Modes of File handling in php
 “w” – Opens a file for write only. If file not exist then new file is created and if file already exists
then contents of file is erased.
 “r” – File is opened for read only.
 “a” – File is opened for write only. File pointer points to end of file. Existing data in file is
preserved.
 “w+” – Opens file for read and write. If file not exist then new file is created and if file already
exists then contents of file is erased.
 “r+” – File is opened for read/write.
 “a+” – File is opened for write/read. File pointer points to end of file. Existing data in file is
preserved. If file is not there then new file is created.
 “x” – New file is created for write only.

fopen() – PHP fopen() function is used to open a file. First parameter of fopen() contains name
of the file which is to be opened and second parameter tells about mode in which file needs to
be opened, e.g.,

<?php

$file = fopen(“demo.txt”,'w');

?>

fread() –– After file is opened using fopen() the contents of data are read using fread(). It takes
two arguments. One is file pointer and another is file size in bytes, e.g.,

<?php

$filename = "demo.txt";

$file = fopen( $filename, 'r' );

$size = filesize( $filename );


$filedata = fread( $file, $size );

?>

3) fwrite() – New file can be created or text can be appended to an existing file using fwrite()
function. Arguments for fwrite() function are file pointer and text that is to written to file. It can
contain optional third argument where length of text to written is specified, e.g.,

<?php

$file = fopen("demo.txt", 'w');

$text = "Hello world\n";

fwrite($file, $text);

?>

4) fclose() – file is closed using fclose() function. Its argument is file which needs to be closed,
e.g.,

<?php

$file = fopen("demo.txt", 'r');

//some code to be executed

fclose($file);

?>

Q-PHP fgets(), fgetc() and feof() file handling


PHP File handling functions :
 fgets() – used to read a single line from a file.
 fgetc() – used to read a single character from a file.
 feof() – used to check ‘end of file’.

*Go through their Syntax also


Q-PHP | Access Specifiers/Access modifier (oops concept in php)

 public - the property or method can be accessed from everywhere. This is default
 protected - the property or method can be accessed within the class and by classes derived from that class
 private - the property or method can ONLY be accessed within the class

Class Member Access Access from own Accessible from derived Accessible by
Specifier class class Object
Private Yes No No
Protected Yes Yes No
Public Yes Yes Yes

Q-Difference between object and class


No. Object Class

1) Object is an instance of a class. Class is a blueprint or template from


which objects are created.

2) Object is a real world entity such as pen, laptop, mobile, Class is a group of similar objects.
bed, keyboard, mouse, chair etc.

3) Object is a physical entity. Class is a logical entity.

4) Object is created through new keyword mainly e.g. Class is declared using class keyword e.g.
Student s1=new Student(); class Student{}

5) Object is created many times as per requirement. Class is declared once.

6) Object allocates memory when it is created. Class doesn't allocated memory when it
is created.

You might also like