Which is the latest version of PHP ?
The latest stable version of PHP is 5.5.14 released at 27 June 2014 .
What is PHP.
PHP is an open source server side scripting language used to develop dynamic websites . PHP stands for Hypertext Preprocessor , also stood for Personal Home Page . Now the implementations of PHP is produced by The PHP group .It was created by Rasmus lerdorf in 1995 . It is a free software released under the PHP license .
Who is the father of PHP ?
What is the current version of Apache ?
The latest stable version of Apache is 2.4.9, released on 17th March 2014.
What is difference between unset and unlink..
Unset is used to delete(destroy) a variable whereas unlink used to delete a file.
Which is the latest version of PHP.
The latest stable version of PHP is 5.4.11 released at 17 January 2013 .
What is the difference between array_merge and array_combine.
array_merge merges the elements of one
or more than one array such that the value of one array appended at the
end of first array. If the arrays have same strings key then the later
value overrides the previous value for that key .
<?php
$array1 = array("course1" => "java","course2" => "sql");
$array2 = array(("course1" => "php","course3" => "html");
$result = array_merge($array1, $array2);
print_r($result);
?>
OUTPUT :
array
(
[course1] => php
[course2] => sql
[course3] => html
)
Array_combine creates a new array by using the key of one array as keys and using the value of other array as values.
<?php
$array1 = array("course1","course2");
$array2 = array(("php","html");
$new_array = array_combine($array1, $array2);
print_r($new_array);
?>
OUTPUT :
array
(
[course1] => php
[course2] => html
)
<?php
$array1 = array("course1" => "java","course2" => "sql");
$array2 = array(("course1" => "php","course3" => "html");
$result = array_merge($array1, $array2);
print_r($result);
?>
OUTPUT :
array
(
[course1] => php
[course2] => sql
[course3] => html
)
Array_combine creates a new array by using the key of one array as keys and using the value of other array as values.
<?php
$array1 = array("course1","course2");
$array2 = array(("php","html");
$new_array = array_combine($array1, $array2);
print_r($new_array);
?>
OUTPUT :
array
(
[course1] => php
[course2] => html
)
What is the difference between session and cookies.
There are some difference between session and cookies thath are as following:-
1 : Session are temporary and Cookies are parmanent.
2 : Session data is store on server while Cookies are store on user's computer.
3 :Cookies contents can be easily modify but to modify Session contents is very hard.
4 :Cookies could be save for future reference but Session couldn't when user close the browser Session data also lost.
1 : Session are temporary and Cookies are parmanent.
2 : Session data is store on server while Cookies are store on user's computer.
3 :Cookies contents can be easily modify but to modify Session contents is very hard.
4 :Cookies could be save for future reference but Session couldn't when user close the browser Session data also lost.
How we declare cookies and how we expire it.
setcookie() function is used to set cookies in php.
To declare Cookies syntax will be:- setcookie(name, value, expire, path, domain);
name : Name of the cookie
value : Value of the cookie
expire : The time for cookie to expire
path : path to save the cookie where we want to save the cookie information
domain : domain name on which we want to save the cookie
e.g : setcookie("username","harry",time()+60*60*60*24);
In the above example the cookie name is username having value harry and set for one day .
To expire cookies we have set the time of cookie in past
To expire Cookies syntax will be: setcookie(name,value,time-3600);
To declare Cookies syntax will be:- setcookie(name, value, expire, path, domain);
name : Name of the cookie
value : Value of the cookie
expire : The time for cookie to expire
path : path to save the cookie where we want to save the cookie information
domain : domain name on which we want to save the cookie
e.g : setcookie("username","harry",time()+60*60*60*24);
In the above example the cookie name is username having value harry and set for one day .
To expire cookies we have set the time of cookie in past
To expire Cookies syntax will be: setcookie(name,value,time-3600);
What is use of var_dump .
var_dump() function is used to display structured information(type and value) about one or more variable.
syntax:- var_dump(variable1,variable2,.....variablen);
e.g <?php
$a=3.1;
$b=true;
var_dump($a,$b);
?>
output : float(3.1)
bool(true)
syntax:- var_dump(variable1,variable2,.....variablen);
e.g <?php
$a=3.1;
$b=true;
var_dump($a,$b);
?>
output : float(3.1)
bool(true)
What is str_replace().
This function replace some characters with some other characters in a string , this function is case sensitive.
syntax:- str_replace(find,replace,string);
find:-required,specifies the value to find.
replace:-required,specifies the value to replace the value in find.
string:-required,specifies the string to searched.
for examlpe:-
<?php
echo str_replace("world","india","hello world");
?>
output:- hello india
syntax:- str_replace(find,replace,string);
find:-required,specifies the value to find.
replace:-required,specifies the value to replace the value in find.
string:-required,specifies the string to searched.
for examlpe:-
<?php
echo str_replace("world","india","hello world");
?>
output:- hello india
What is the difference between include() and require().
include() function gives the warning when specified file not found but all script will be continually executed.
e.g. <?php
include("filename.php");
echo "hello";
?>
output:- hello
In the above example if file not found then it gives warning and print the hello because warning does not stop script and echo will be execute.
require() function gives the fatal error when specifies file is not found and stop the script.
e.g. <?php
require("filename.php");
echo "hello";
?>
output:- it gives fatal error and stop the script ,echo will not be executed.
e.g. <?php
include("filename.php");
echo "hello";
?>
output:- hello
In the above example if file not found then it gives warning and print the hello because warning does not stop script and echo will be execute.
require() function gives the fatal error when specifies file is not found and stop the script.
e.g. <?php
require("filename.php");
echo "hello";
?>
output:- it gives fatal error and stop the script ,echo will not be executed.
What is final class.
final class is a class that can not be inherited.Its protect the methods of class to be overriden by the child classes.
e.g. final class baseclass
{
public function mymethod() {
echo "baseclass method";
}
}
class derivedclass extends baseclass
{
public function mymethod() {
echo "derivedclass method";
}
}
$c= new derivedclass();
$c->mymethod();
In the above example base class is declared as final and hence can not be inherited.
derived class tries to extends baseclass then compile error will be generated.
e.g. final class baseclass
{
public function mymethod() {
echo "baseclass method";
}
}
class derivedclass extends baseclass
{
public function mymethod() {
echo "derivedclass method";
}
}
$c= new derivedclass();
$c->mymethod();
In the above example base class is declared as final and hence can not be inherited.
derived class tries to extends baseclass then compile error will be generated.
What is difference between abstract class and interface classes.
Interface : An interface does not
contain any code,it contain only declaration of
methods,properties,events. Interfaces allow us to code which specifies
which methods a class must have implement . Interfaces defines with the
word interface . All methods in interfaces must be public
e.g : interface myItem
{
void Id();
string description();
string Runtest(int testnumber);
}
Abstract class : Abstract classes are look like interfaces.Abstract classes may contain code although it may also have abstract method that do not have code. Abstract classes defines only signature of the method ,not implementation. The child class which inherit the abstarct class must define all the abstarct methods of its parent class .
e.g abstract class myItem
{
abstract protected function getitem();
abstract protected function setitem();
}
e.g : interface myItem
{
void Id();
string description();
string Runtest(int testnumber);
}
Abstract class : Abstract classes are look like interfaces.Abstract classes may contain code although it may also have abstract method that do not have code. Abstract classes defines only signature of the method ,not implementation. The child class which inherit the abstarct class must define all the abstarct methods of its parent class .
e.g abstract class myItem
{
abstract protected function getitem();
abstract protected function setitem();
}
What is difference between echo() and print().
echo() and print() function both are used to show the output on the visitors screen but in echo we can take one or more parameters.
print() has a return value of true or false whereas echo has a void return type.
echo() is slightly faster than print.
print() has a return value of true or false whereas echo has a void return type.
echo() is slightly faster than print.
What is the difference between PHP4 and PHP5.
There are some difference between PHP4 and PHP5 that are as following:-
1) In PHP5 abstract classes are used but not used in PHP4.
2) In PHP5 interfaces are used but not used in PHP4.
3) In PHP5 visibility are used but not used in PHP4.
4) In PHP5 magic methods are used but not uesd in PHP4.
5) In PHP5 typehinting are used but not used in PHP4.
6) In PHP5 cloning are used but not used in PHP4.
7) In PHP5 construtor are written as __construct keyword but in PHP4 are written as class name.
1) In PHP5 abstract classes are used but not used in PHP4.
2) In PHP5 interfaces are used but not used in PHP4.
3) In PHP5 visibility are used but not used in PHP4.
4) In PHP5 magic methods are used but not uesd in PHP4.
5) In PHP5 typehinting are used but not used in PHP4.
6) In PHP5 cloning are used but not used in PHP4.
7) In PHP5 construtor are written as __construct keyword but in PHP4 are written as class name.
How many types of errors in PHP.
There are mainly three types of error in php. These are -
(1) Notice error
(2) Warning error
(3) Fatal error
Notice error happened when a variable not decleared but it is used.
Warning error occurred when a package not defined and some functionality has been used in the program.These are not serious errors, they continue the execution of script.
And Fatal error are those errors when an object call a class and the class not present there.These errors are serious error which can stop the execution of script
(1) Notice error
(2) Warning error
(3) Fatal error
Notice error happened when a variable not decleared but it is used.
Warning error occurred when a package not defined and some functionality has been used in the program.These are not serious errors, they continue the execution of script.
And Fatal error are those errors when an object call a class and the class not present there.These errors are serious error which can stop the execution of script
Why do we use ob_start().
Ob_start used to active the output
buffering .When output buffering is on all output of the page sent at
one time to the browser ,otherwise sometimes we face headers already
sent type errors.
What is a .htacces file.
.htaccess is a configuration file
running on Apache server.These .htaccess file used to change the
functionality and features of apache web server .
e.g .htaccess file used for url rewrite .
.htaccess file used to make the site password protected.
.htaccess file can restrict some ip addresses ,so that on restricted ip adresses site will not open.
e.g .htaccess file used for url rewrite .
.htaccess file used to make the site password protected.
.htaccess file can restrict some ip addresses ,so that on restricted ip adresses site will not open.
Is PHP an interpreted language or compiler language.
PHP is an interpreted language.
What is the difference between compiler language and interpreted language.
Interpreted language executes line by line , if there is some error on a line it stops the execution of script.
Compiler language can execute the whole script at a time and gives all the errors at a time. It does not stops the execution of script ,if there is some error on some line.
Compiler language can execute the whole script at a time and gives all the errors at a time. It does not stops the execution of script ,if there is some error on some line.
What are web services in PHP.
Web services converts our applicaton into a
web-application ,which can publish its functions and messages to the
internet users.The main web services platform is XML and HTTP.Web
services can be published ,found and used through web.
What is static methods and properties in PHP.
A static method is accessible without
needing instantiation of a class. It means there is no need to make an
object to call the static methods .Static methods and properties can
be directly call from its class name with (::) a scope resolution
operator. They cannot be call from the object of its class. We need
static methods to overcome long overhead of instantiation of classes .
e.g
<?php
Class foo
{
public static $variable_name = 'it is a static variable';
}
echo foo :: $variable_name; // Output : it is a static varaible
?>
e.g
<?php
Class foo
{
public static $variable_name = 'it is a static variable';
}
echo foo :: $variable_name; // Output : it is a static varaible
?>
What are magic methods in PHP..
Magic methods are very easy to identify,
that every magical method name is started with double underscore(
__)sign. We can not declare any user-defined functions with __ sign.
Some magic methods are :
__construct() , __destruct() , __call() , __callStatic() , __get(), __set() , __isset() ,__unset()
, __sleep() , __wakeup(), __toString() , __invoke() , __set_state() , __clone().
Some magic methods are :
__construct() , __destruct() , __call() , __callStatic() , __get(), __set() , __isset() ,__unset()
, __sleep() , __wakeup(), __toString() , __invoke() , __set_state() , __clone().
What is the difference between GET and POST methods.
GET Method:
1) All the name value pairs are submitted as a query string in URL.
2) It's not secured.
3) Length of the string is restricted about 256.
4) If method is not mentioned in the Form tag, this is the default method used.
5) Data is always submitted in the form of text.
POST Method:
1) All the name value pairs are submitted in the Message Body of the request.
2) Length of the string (amount of data submitted) is not restricted.
3) Post Method is secured because Name-Value pairs cannot be seen in location bar of the web browser.
4) If post method is used and if the page is refreshed it would prompt before the request is resubmitted.
5) If the service associated with the processing of a form has side effects (for example, modification of a
database or subscription to a service), the method should be POST.
1) All the name value pairs are submitted as a query string in URL.
2) It's not secured.
3) Length of the string is restricted about 256.
4) If method is not mentioned in the Form tag, this is the default method used.
5) Data is always submitted in the form of text.
POST Method:
1) All the name value pairs are submitted in the Message Body of the request.
2) Length of the string (amount of data submitted) is not restricted.
3) Post Method is secured because Name-Value pairs cannot be seen in location bar of the web browser.
4) If post method is used and if the page is refreshed it would prompt before the request is resubmitted.
5) If the service associated with the processing of a form has side effects (for example, modification of a
database or subscription to a service), the method should be POST.
What are access control modifiers in php.
Keywords public,protected and private
are the three types of access control modifiers in php.With the help of
these keywords we can manage the accessing of a method or property
of a class in php
What is difference between public, private and protected in php.
Public :
The items which are declared public can be access from everywhere ie access from inside the class ,access in inherited class and access from outside the class.
Protected :
The items which are declared protected can be access inside the class that defines the item and can acess in its child classes (ie access in its inherited class) .
Private :
The items which are declared private can only be access inside its class that defines the item.
The items which are declared public can be access from everywhere ie access from inside the class ,access in inherited class and access from outside the class.
Protected :
The items which are declared protected can be access inside the class that defines the item and can acess in its child classes (ie access in its inherited class) .
Private :
The items which are declared private can only be access inside its class that defines the item.
How can we get all the properties of browser in PHP.
We can get the browser properties in PHP by :
<?php
$_SERVER ['HTTP_USER_AGENT'] ;
?>
<?php
$_SERVER ['HTTP_USER_AGENT'] ;
?>
How to get difference between two dates.
$firstdate = "2010-10-07";
$seconddate = "2014-03-10";
$differnce = abs(strtotime($date2) - strtotime($date1));
$years = floor($differnce / (365*60*60*24));
$months = floor(($differnce - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($differnce- $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d daysn", $years, $months, $days);
How to get the names of all included and required files for a particular page in PHP.$seconddate = "2014-03-10";
$differnce = abs(strtotime($date2) - strtotime($date1));
$years = floor($differnce / (365*60*60*24));
$months = floor(($differnce - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($differnce- $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d daysn", $years, $months, $days);
No comments:
Post a Comment