builder : make and return one object various ways.
factory method: methods to make and return components of one object various ways.
prototype: make a object by the cloning of object which u said as a prototype.
singletone : the class distributes the class of itself.
6. find the difference between two dates
$date1 = "2007-03-24";
$date2 = "2009-06-26";
$diff = abs(strtotime($date2) - strtotime($date1));
//abs absolute value
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d days\n", $years, $months, $days);
7.What is Exception Handling.
With php 5 came a new object oriented way to dealing with error.
Exception Handling is used to change the normal flow of code execution if a specified
error is occur.
This is what normally happens when an exception is triggered:
- The current code state is saved
- The code execution will switch to a predefined (custom) exception handler function.
- Depending on the situation, the handler may then resume the execution from the saved code state, terminate the script execution or continue the script from a different location in the code.
We will show different error handling methods:
- Basic use of Exceptions
- Creating a custom exception handler
- Multiple exceptions
- Re-throwing an exception
- Setting a top level exception handler
Note: Exceptions should only be used with error conditions, and should not be used to jump to another place in the code at a specified point.
function checkNumber($number){
if($number>1){
throw new Exception ("Value must be 1 or less then 1");
}
return true;
}
try{
checkNumber(2);
print "the try message is display";
}
catch(Exception $number){
echo "Message".$number->getMessage();
}
8.How validate email address except regular expressions.
filter_var($email, FILTER_VALIDATE_EMAIL);
function ($email){
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
print $email. "is not valid email id";
}
else{
print "email valid";
}
No comments:
Post a Comment