PHP - Interview questions and answers for experienced
What's the difference between include and require?
If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.What are the differences between Get and post methods.
i. GET Method have some limit like only 2Kb data able to send for request. But in POST method unlimited data can we sendii. When we use GET method requested data show in url but Not in POST method so POST method is good for send sensetive request
What is the difference between PHP and JavaScript?
Javascript is a client side scripting language, so javascript can make popups and other things happens on someone’s PCWhile PHP is server side scripting language so it does every stuff with the server.What are the advantages of MySQL and PHP?
Both of them are open source software (so free of cost), support cross platform. PHP is faster then ASP and JSP.Is variable name casesensitive ? could we start a variable with number like $4name ? What is the difference between $name and $$name? How to swap two variables without using 3rd temp variable
Yes variable name casesensitive and we can not start a variable with number like $4name as A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
where as $$ is variable of variable $name is variable where as $$name is variable of variable
like $name=sonia and $$name=singh so $sonia value is singh.
we can swap two variables by adding and subtracting method like below
$a=10,$b=5;
$a=$b+$a;//means $a=15 here
$b=$a-$b; //means $b=15-5=10
$a=$a-$b;// means $a=15-10=5
What is use of header() function in php ? What the Limitation of HEADER()?
In PHP Important to notice the Limitation of HEADER() function is that header() must be called before any actual output is send. Means must use header function before HTML or any echo stateamentThere are Number of Use of HEADER() function in php like below
The header() function use to sends a raw HTTP header to a client.
We can use herder() function for redirection of pages.
Use for refresh the page on given time interval automatically.
To send email header content like cc, bcc , reply to etc data and lot more
What is htaccess? Why do we use this and Where?
.htaccess files are configuration files of Apache Server which providea way to make configuration changes on a per-directory basis. A file,
containing one or more configuration directives, is placed in a particular
document directory, and the directives apply to that directory, and all
subdirectories thereof.
What is the use of friend function?
Sometimes a function is best shared among a number of differentclasses. Such functions can be declared either as member functions of
one class or as global functions. In either case they can be set to be
friends of other classes, by using a friend specifier in the class that
is admitting them. Such functions can use all attributes of the class
which names them as a friend, as if they were themselves members of that
class.
A friend declaration is essentially a prototype for a member function,
but instead of requiring an implementation with the name of that class
attached by the double colon syntax, a global function or member
function of another class provides the match.
What are the different types of errors in PHP?
Three are three types of errors:1. Notices: These are trivial,non-critical errors that PHP encounters while executing a script – for
example, accessing a variable that has not yet been defined. By default,
such errors are not displayed to the user at all – although, as you will
see, you can change this default behavior.2. Warnings: These are more serious errors – for example, attempting
to include() a file which does not exist. By default, these errors are
displayed to the user, but they do not result in script termination.3. Fatal errors: These are critical errors – for example,
instantiating an object of a non-existent class, or calling a
non-existent function. These errors cause the immediate termination of
the script, and PHP's default behavior is to display them to the user
when they take place.
What is the functionality of the function strstr and stristr?
strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to the end of string.$email= 'sonialouder@gmail.com';
$domain = strstr($email, '@');
echo $domain; // prints @gmail.com
here @ is the needle
stristr is case-insensitive means able not able to diffrenciate between a and A
in PHP for pdf which library used?
The PDF functions in PHP can create PDF files using the PDFlib library With version 6, PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4. There is also the » Panda module. FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.for image work which library?
we will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.what is magic quotes?
Magic Quotes is a process that automagically escapes ncoming data to the PHP script. Its preferred to code with magic quotes off and to instead escape the data at runtime, as needed. This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.what is the major php security hole? how to avoid?
1. Never include, require, or otherwise open a file with a filename based on user input, without thoroughly checking it first.2. Be careful with eval() Placing user-inputted values into the eval() function can be extremely dangerous. You essentially give the malicious user the ability to execute any command he or she wishes!
3. Be careful when using register_globals = ON It was originally designed to make programming in PHP easier (and that it did), but misuse of it often led to security holes
4. Never run unescaped queries
5. For protected areas, use sessions or validate the login every time.
6. If you don't want the file contents to be seen, give the file a .php extension.
In PHP what is the difference between a Class and an Interface?
Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decide not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.Explain how a PHP session works?
A PHP session cookie is set in the clients browser, on every request the client sends that cookie to the server. PHP then uses that cookie to select the corresponding session information. By default PHP session_start() will store session data in files, you can also store sessions in a database.How do you load classes in PHP?
They are trying to gauge your understanding of how class auto loading works. Review the "autoload" and "spl_autoload_register" function (note:you should use the later). The autoload function basically triggers a function when a class is instantiated, you can put whatever logic you like in it but generally you want to include the class file based on some sort of naming convention.What is the Scope Resolution Operator?
"::" double colons is the scope operator it is used to call methods of a class that has not been instantiated. You should also understand static methods and how they differ from regular methods.Explain the difference between $message and $$message?
$message is used to store variable data. $$message can be used to store variable of a variable. Data stored in $message is fixed while data stored in $$message can be changed dynamically.E.g. $var1 = ‘Variable 1’
$$var1= ‘variable2’
This can be interpreted as $ Variable 1=‘variable2’;
For me to print value of both variables, I will write
$var1 $($var1)