Sei sulla pagina 1di 12

UNIT – III

1). What is Object Oriented Programming?


Ans:- Object Oriented Concepts:-
Before we go in detail, lets define important terms related to Object Oriented
Programming.
 Class − This is a programmer-defined data type, which includes local functions as
well as local data. You can think of a class as a template for making many
instances of the same kind (or class) of object.
 Object − An individual instance of the data structure defined by a class. You
define a class once and then make many objects that belong to it. Objects are also
known as instance.
 Member Variable − These are the variables defined inside a class. This data will
be invisible to the outside of the class and can be accessed via member functions.
These variables are called attribute of the object once an object is created.
 Member function − These are the function defined inside a class and are used to
access object data.
 Inheritance − When a class is defined by inheriting existing function of a parent
class then it is called inheritance. Here child class will inherit all or few member
functions and variables of a parent class.
 Parent class − A class that is inherited from by another class. This is also called a
base class or super class.
 Child Class − A class that inherits from another class. This is also called a
subclass or derived class.
 Polymorphism − This is an object oriented concept where same function can be
used for different purposes. For example function name will remain same but it
make take different number of arguments and can do different task.
 Overloading − a type of polymorphism in which some or all of operators have
different implementations depending on the types of their arguments. Similarly
functions can also be overloaded with different implementation.
 Data Abstraction − Any representation of data in which the implementation
details are hidden (abstracted).
 Encapsulation − refers to a concept where we encapsulate all the data and
member functions together to form an object.
 Constructor − refers to a special type of function which will be called
automatically whenever there is an object formation from a class.
 Destructor − refers to a special type of function which will be called
automatically whenever an object is deleted or goes out of scope.

3). Explian Error-Reporting().


Ans.:- PHP Error Introduction :--
The error functions are used to deal with error handling and logging.
The error functions allow us to define own error handling rules, and modify the way
the errors can be logged.
The logging functions allow us to send messages directly to other machines, emails,
or system logs.
The error reporting functions allow us to customize what level and kind of error
feedback is given.
PHP error_reporting() Function :--
Examle:-
Specify different error level reporting:--
<?php
// Turn off error reporting
error_reporting(0);
// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Report all errors
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>

4). Explian Printing Function on short.


Ans.:-
Definition and Usage:-
The print() function outputs one or more strings.
Note: The print() function is not actually a function, so you are not required to use
parentheses with it.
Tip: The print() function is slightly slower than echo().
Syntax:-
Print(strings)
Exapmle:-
<?php
print "Hello world!";
?>

5). What is Perl-Compatible Regular Expressions?


Ans.:- PERL Regular Expressions:-
Perl regular expressions are similar to their POSIX counterparts. The POSIX
syntax can be used almost interchangeably with the Perl-style regular expression
functions. In fact, you can use any of the quantifiers introduced in the previous
POSIX section.
Lets give explanation for few concepts being used in PERL regular expressions.
After that we will introduce you wih regular expression related functions.
Meta character:-
A meta character is simply an alphabetical character preceded by a backslash that acts to
give the combination a special meaning.
For instance, you can search for large money sums using the '\d' meta
character: /([\d]+)000/, Here \d will search for any string of numerical character.
Following is the list of meta characters which can be used in PERL Style Regular
Expressions.
Character Description
. a single character
\s a whitespace character (space, tab, newline)
\S non-whitespace character
\d a digit (0-9)
\D a non-digit
\w a word character (a-z, A-Z, 0-9, _)
\W a non-word character
[aeiou] matches a single character in the given set
[^aeiou] matches a single character outside the given set
(foo|bar|baz) matches any of the alternatives specified
Modifiers:-
Several modifiers are available that can make your work with regexps much easier, like
case sensitivity, searching in multiple lines etc.
Modifier Description
i Makes the match case insensitive
m Specifies that if the string has newline or carriage
return characters, the ^ and $ operators will now
match against a newline boundary, instead of a
string boundary
o Evaluates the expression only once
s Allows use of . to match a newline character
x Allows you to use white space in the expression for clarity
g Globally finds all matches
cg Allows a search to continue even after a global match fails

6). Explain File Reading Function.


Ans.:- PHP readfile() Function:-
The readfile() function reads a file and writes it to the output buffer.
Assume we have a text file called "webdictionary.txt", stored on the server, that
looks like this:
AJAX = Asynchronous JavaScript and XML
CSS = Cascading Style Sheets
HTML = Hyper Text Markup Language
PHP = PHP Hypertext Preprocessor
SQL = Structured Query Language
SVG = Scalable Vector Graphics
XML = EXtensible Markup Language
The PHP code to read the file and write it to the output buffer is as follows
(the readfile() function returns the number of bytes read on success):
Example:-
<?php
echo readfile("webdictionary.txt");
?>

7). Explain Directory Function.


Ans.:- PHP Directory Introduction:-
The directory functions allow you to retrieve information about directories and their
contents.
PHP Directory Functions:-
Function Description
chdir() Changes the current directory
chroot() Changes the root directory
closedir() Closes a directory handle
dir() Returns an instance of the Directory class
getcwd() Returns the current working directory
opendir() Opens a directory handle
readdir() Returns an entry from a directory handle
rewinddir() Resets a directory handle
scandir() Returns an array of files and directories of a specified directory

8). Define Network Function.


Ans.:- Network Function (NF) :- A functional building block within
a network infrastructure, which has well-defined external interfaces and a well-
defined functional behavior. In practical terms, a Network Function is today often
a network node or physical appliance.
List of Functions :-
PHP − indicates the earliest version of PHP that supports the function.

Sr.No Function & Description

1 checkdnsrr
It checks the DNS record of corresponding the host or ip address.

2 closelog
It closing the connection of system logger

3 define_syslog_variables
Initializes the syslog variable

4 fsockopen
It is used to open internet or Unix domain socket connections

5 gethostbyaddr
It returns the error code from the last connection

6 gethostbyname
It is used to get the internet host name which has given by IP
Address.

7 gethostbynamel
It is used to get a list of the IPV4 addresses which has given by Host
name

8 gethostname
It is used to get the host name

9 getmxrr
It is used to get the MX records to Host

10 getprotobyname
It is used to get Protocal number which has associated with protocal
name
11 getprotobynumber
It is used to fetchs all result rows and returns the result set as an
associative array

12 getservbyname
It is used to get Protocal name which has associated with protocal
number

13 getservbyport
It is used to get internet services which has corresponding to port
number.

14 header_register_callback
It will register the function that will be called when PHP start sending
output.

15 header_remove
It is used to remove previously set headers

16 header
It is used to send the row of HTTP Headers.

17 headers_list
It is used to returns a list of repose headers sent

18 headers_sent
It will check whether header have been sent or not.

19 http_response_code.
It used to get or set the HTTP Response.

20 inet_ntop
It used to convert internet package to human readable formate.

21 inet_pton
It used to convert human readable Ip address to in_addr format.

22 ip2long
It used to convert ipv4 address to long integer.

23 long2ip
It used to convert long integer value to Ipv4 address.

24 openlog
It used to open connection to system logger.

25 pfsockopen
It used to open internet or unix domain socket.

26 setcookie
It used to set the cookies.

27 setrawcookie
It used to set the cookies.

28 socket_set_blocking
It is an alias of stream_set_blocking(), It has block or unblock options
for stram mode.

9). Explain Other Method of Error Handling.

Ans.:- The default error handling in PHP is very simple. An error message with filename,
line number and a message describing the error is sent to the browser.
PHP Error Handling:-
When creating scripts and web applications, error handling is an important part. If
your code lacks error checking code, your program may look very unprofessional
and you may be open to security risks.
This tutorial contains some of the most common error checking methods in PHP.
We will show different error handling methods:
 Simple "die()" statements
 Custom errors and error triggers
 Error reporting
Basic Error Handling: Using the die() function
The first example shows a simple script that opens a text file:
<?php
$file=fopen("welcome.txt","r");
?>
To prevent the user from getting an error message like the one above, we test
whether the file exist before we try to access it:
<?php
if(!file_exists("welcome.txt"))
{
die("File not found");
}
Else
{
$file=fopen("welcome.txt","r");
}
?>
Creating a Custom Error Handler
Creating a custom error handler is quite simple. We simply create a special
function that can be called when an error occurs in PHP.
This function must be able to handle a minimum of two parameters (error level
and error message) but can accept up to five parameters (optionally: file, line-
number, and the error context):
Syntax:-
error_function(error_level,error_message,
error_file,error_line,error_context)

10). Write notre on General Troubleshooting strategies.


Ans.:- Troubleshooting is the process of identifying, planning and resolving a problem,
error or fault within a software or computer system. It enables the repair and
restoration of a computer or software when it becomes faulty, unresponsive or acts
in an abnormal way.

Techopedia explains Troubleshooting:-


Troubleshooting is primarily done to keep a system or software in desired condition,
specifically when it encounters or exhibits a problem. It is a systematic approach
done within one or more phases depending on the complexity of a problem.
Typically, the first step involves identifying what the problem is followed by
coming up with a solution to counteract the problem and then implementing that
solution. However, there can be more than one reason for the problem, which will
require a more complex solution. An individual troubleshooting such a problem
might test for different solutions to eliminate the problem or fault.
UNIT - IV

1). How To send E-mail with PHP?


Ans.:- PHP makes use of mail() function to send an email. This function requires three
mandatory arguments that specify the recipient's email address, the subject of the
the message and the actual message additionally there are other two optional
parameters.
mail( to, subject, message, headers, parameters );
Here is the description for each parameters.
Sr.No Parameter & Description

1 to
Required. Specifies the receiver / receivers of the email

2 subject
Required. Specifies the subject of the email. This parameter
cannot contain any newline characters

3 message
Required. Defines the message to be sent. Each line should
be separated with a LF (\n). Lines should not exceed 70
characters

4 headers
Optional. Specifies additional headers, like From, Cc, and
Bcc. The additional headers should be separated with a
CRLF (\r\n)

5 parameters
Optional. Specifies an additional parameter to the send mail
program
As soon as the mail function is called PHP will attempt to send the email then it
will return true if successful or false if it is failed.
Multiple recipients can be specified as the first argument to the mail() function in
a comma separated list.

2). Explian DTDs.


Ans.:-A DTD is a Document Type Definition.
A DTD defines the structure and the legal elements and attributes of an XML
document
With a DTD, independent groups of people can agree on a standard DTD for
interchanging data.
An application can use a DTD to verify that XML data is valid.
If the DTD is declared inside the XML file, it must be wrapped inside the
<!DOCTYPE> definition:
XML document with an internal DTD
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>

3). Explian SAX.


Ans.:- SAX parser has used to parse the xml file and better for memory management
than sample xml parser and DOM. It does not keep any data in memory so it can
be used for very large files. Following example will show how to get data from
xml by using SAX API.
SAX.php
Php file should as follows −
<?php
//Reading XML using the SAX(Simple API for XML) parser
$tutors = array();
$elements =null;
// Called to this function when tags are opened
function startElements($parser, $name, $attrs){
global $tutors, $elements;

if(!empty($name)){
if($name =='COURSE'){
// creating an array to store information
$tutors []= array();
}
$elements = $name;
}
}
// Called to this function when tags are closed
function endElements($parser, $name){
global $elements;
if(!empty($name)){
$elements =null;
}
}
// Called on the text between the start and end of the tags

function characterData($parser, $data){


global $tutors, $elements;
if(!empty($data)){
if($elements =='NAME'|| $elements =='COUNTRY'|| $elements =='EMAIL'|| $elements
=='PHONE'){
$tutors[count($tutors)-1][$elements]= trim($data);
}
}
}

11). Explian Troubleshooting in JavaScript.


Ans.:- Debugging is not easy. But fortunately, all modern browsers have a built-in
JavaScript debugger.
Built-in debuggers can be turned on and off, forcing errors to be reported to the user.
With a debugger, you can also set breakpoints (places where code execution can be
stopped), and examine variables while the code is executing.
Normally, otherwise follow the steps at the bottom of this page, you activate
debugging in your browser with the F12 key, and select "Console" in the debugger
menu.
The console.log() Method:-
If your browser supports debugging, you can use console.log() to display JavaScript
values in the debugger window:
Example:-
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<script>
a = 5;
b = 6;
c = a + b;
console.log(c);
</script>
</body>
</html>

10). Explain Gotches In Javascript.


Ans.:- JavaScript Gotchas :-
We all know that JavaScript can trip you up. Here are a 16 common traps that can
trip you up when coding javascript. You likely know most of the code on the page,
but if you keep these 16 gotchas in your mind, coding and debugging will be less of
a headache:

Case sensitivity : Variable names, properties and methods are all case sensitive.
 Mismatching quotes, parenthesis or curly braces will throw an error.
 Conditional Statements : 3 common gotchas.
 Line breaks: Always end statements in semi-colons to avoid common line
break issues.
 Punctuation:Trailing commas in object declarations will trip you up.
 HTML id conflicts.
 Variable Scope: global versus local scope.
 string replace function isn’t global.
 parseInt should include two arguments.
 ‘this’ and binding issues.
 Function overloading: Overwriting functions, as overloading doesn’t exist.
 Setting default values for parameters in case you omit them.
 For each loops are for objects, not arrays.
 switch statements are a little tricky.
 Always check for Undefined before checking for null.
 Function location may matter.

Potrebbero piacerti anche