PHP interview questions
Q 1- What are magic methods?
Ans:
Magic methods are the members functions that is available to all the instance of class Magic methods always starts with “__”. Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()
Q 2- What is magic quotes?
Ans:
Magic Quotes is a process that automagically escapes incoming data to the PHP script. It’s 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.
Q 3- What is design pattern? singleton pattern?
Ans:
A design pattern is a general reusable solution to a commonly occurring problem in software design.
The Singleton design pattern allows many parts of a program to share a single resource without having to work out the details of the sharing themselves.
Q 4- Types of error? how to set error settings at run time?
Ans:
Here are three basic types of runtime errors in PHP:
i. 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 you can change this default behaviour.
ii. 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.
iii. 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 behaviour is to display them to the user when they take place.
Q 5- what is cross site scripting? SQL injection?
Ans:
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users. Examples of such code include HTML code and client-side scripts.
SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed
Q 6- what is URL rewriting?
Ans:
Using URL rewriting we can convert dynamic URl to static URL. Static URLs are known to be better than Dynamic URLs because of a number of reasons
i. Static URLs typically Rank better in Search Engines.
ii. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages.
iii. Static URLs are always more friendlier looking to the End Users.
Q 7- What is the major php security hole? how to avoid?
Ans:
a) Never include, require, or otherwise open a file with a filename based on user input, without thoroughly checking it first.
b) 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!
c) 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.
d) Never run unescaped queries.
e) For protected areas, use sessions or validate the login every time.
f) If you don’t want the file contents to be seen, give the file a .php extension.
Q 8- What is MVC? why its been used?
Ans:
Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model.
Q 9- What is framework? how it works? what is advantage?
Ans:
In general, a framework is a real or conceptual structure intended to serve as a support or guide for the building of something that expands the structure into something useful. Advantages : Consistent Programming Model Direct Support for Security Simplified Development Efforts Easy Application Deployment and Maintenance.
Q 10- What is CURL?
Ans:
CURL stands for Client URL Library.
CURL is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos…), file transfer resume, proxy tunneling and a busload of other useful tricks.
CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.
Q 11 – What is XML-RPC ?
Ans:
XML-RPC is a remote procedure call protocol which uses XML to encode its calls and HTTP as a transport mechanism. An XML-RPC message is an HTTP-POST request. The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML.
Q 12 – What is the difference between htmlentities() and htmlspecialchars()?
Ans :
i) htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used).
ii) htmlentities() – Convert ALL special characters to HTML entities.
Follow @phpzag

Thanks for taking this possibility to talk about this, I’m strongly about this and I reap the benefits of garden greenhouse structures this subject. If at all possible, while you gain data, please update this website with new information. I’ve discovered it extremely useful.
Wonderful web site. Plenty of useful info here. Iˇm sending it to several pals ans additionally sharing in delicious. And naturally, thanks for your sweat!
Hello, it really interesting, thanks http://www.phpzag.com
Este artículo es digno de marcar en mi opinión. Vale la pena ahorrar para futuras referencias. Es una lectura fascinante, con muchos puntos válidos para la contemplación. Tengo que coincidir en casi todos los puntos hechos en este artículo.
I really wanted to send a small word to say thanks to you for the fantastic points you are writing on http://www.phpzag.com. My time-consuming internet lookup has at the end been honored with extremely good ideas to exchange with my pals. I ‘d express that many of us site visitors actually are extremely endowed to exist in a notable community with so many lovely individuals with useful points. I feel really fortunate to have used your webpage and look forward to so many more fun moments reading here. Thanks a lot again for a lot of things.
Great post. I used to be checking continually this blog for impressed! Incredibly useful data specifically the very last part I care for similarly info much. I became looking for this kind of info for the very long time. Many thanks and all the best ..
really nice content
I am often to blogging and i really appreciate your content. The article has really highs my curiosity. I am going to take a note of your site and make checking for first time information.
My dear goodness! an incredible article guy. Thank you Even so am encountering issue with your rss. Do not know why Unable to subscribe to it. Is there any person getting the exact same rss dilemma? Anyone who is aware kindly react. Thnkx
Excellent post. I was examining constantly this site and I am pleased! Extremely helpful information particularly the last component :I maintain such information significantly. I was in search of this selected information to get a very long time. Thank you and all the best ..
Just desire to point out your article is incredible. The quality in your article is simply neat and i might assume you are an expert about this subject. Well with your permission allow me to get your nourish to keep up-to-date with approaching post. Cheers a million and also please continue the pleasant work.
I do consider all the ideas you have offered for your post. They’re really convincing and will certainly work. Nonetheless, the posts are too short for newbies. Could you please lengthen them a bit from subsequent time? Thank you for the post.