PHP Viva Questions
PHP Viva Questions
PHP Viva Questions
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.
There are 8 data types in PHP which are used to construct the variables:
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.
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 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.
__destruct() __sleep()
__construct() __wakeup()
__call() __toString()
__get() __invoke()
__set() __set_state()
__isset() __clone()
__unset() __debugInfo()
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.
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.
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.
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.
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
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";
?>
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
fwrite($file, $text);
?>
4) fclose() – file is closed using fclose() function. Its argument is file which needs to be closed,
e.g.,
<?php
fclose($file);
?>
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
2) Object is a real world entity such as pen, laptop, mobile, Class is a group of similar objects.
bed, keyboard, mouse, chair etc.
4) Object is created through new keyword mainly e.g. Class is declared using class keyword e.g.
Student s1=new Student(); class Student{}
6) Object allocates memory when it is created. Class doesn't allocated memory when it
is created.