PHP Interview Questions and Answers
Q1. What is PHP?
Ans: PHP is a server side prearranging language regularly utilized for web applications. PHP has numerous systems and cms for making websites.Even a non specialized individual can cretae destinations utilizing its CMS.WordPress,osCommerce are the famus CMS of php.It is additionally an item situated programming language like java,C-sharp etc.It is extremely simple for learning.
Q2. What are the normal use of PHP?
Ans: Common purposes of PHP −
PHP performs framework capabilities, for example from documents on a framework it can make, open, read, compose, and close them.
PHP can deal with structures, for example assemble information from documents, save information to a record, through email you can send information, return information to the client.
You add, erase, change components inside your data set through PHP.
Access treats factors and set treats.
Utilizing PHP, you can limit clients to get to certain pages of your site.
It can scramble information.
Q3. In what number of ways you can implant PHP code in a HTML page?
Ans: All PHP code should be incorporated inside one of the three exceptional markup labels ate are perceived by the PHP Parser.
<?PHP code goes here ?> <? PHP code goes here ?> <script language="php"> PHP code goes here </script> Most normal tag is the <?php...
Q4. What is the utilization of "reverberation" in php?
Ans: It is utilized to print an information in the site page, Example: <?php reverberation 'Vehicle protection'; ?> , The accompanying code print the text in the page
Q5. How to incorporate a document to a php page?
Ans: We can incorporate a document utilizing "incorporate() " or "require()" capability with record way as its boundary.
Q6. require_once(), require(), include().What is distinction between them?
Ans: require() incorporates and assesses a particular record, while require_once() does that provided that it has not been incorporated previously (in total agreement). In this way, require_once() is prescribed to utilize when you need to incorporate a document where you have a great deal of capabilities for instance. This way you ensure you do exclude the record more times and you won't get the "capability re-pronounced" mistake.
Q7. Contrasts among GET and POST techniques ?
Ans: We can send 1024 bytes utilizing GET technique however POST strategy can move enormous measure of information and POST is the safe technique than GET strategy .
Q8. What is the distinction among Session and Cookie?
Ans: The fundamental distinction among meetings and treats is that meetings are put away on the waiter, and treats are put away on the client's PCs in the text document design. Treats can't hold different variable while meeting can hold numerous variables..We can set expiry for a cookie,The meeting just remaining parts dynamic as long as the program is open.Users don't approach the information you put away in Session,Since it is put away in the server.Session is mostly utilized for login/logout reason while treats utilizing for client movement following
Q9. What is the utilization of detonate() capability ?
Ans: Syntax : exhibit detonate ( string $delimiter , string $string [, int $limit ] );
This capability breaks a string into an exhibit. Every one of the exhibit components is a substring of string framed by parting it on limits shaped by the string delimiter.
Q10. What is the significance of "technique" characteristic in a html structure?
Ans: "technique" quality decides how to send the structure information into the server.There are two strategies, get and post. The default technique is get.This sends the structure data by attaching it on the URL.Information sent from a structure with the POST strategy is imperceptible to other people and has no restrictions on how much data to send.
Q11. Characterize Object-Oriented Methodology
Ans: Object direction is a product/Web improvement strategy that depends on the demonstrating a certifiable system.An object is the center idea engaged with the item direction. An item is the duplicate of this present reality enity.An object situated model is an assortment of articles and its between connections
Q12. Contrast among mysql_connect and mysql_pconnect?
Ans: There is a decent page in the php manual regarding the matter, in short mysql_pconnect() makes a determined association with the data set which implies a SQL connect that don't close when the execution of your content finishes. mysql_connect()provides just for the databasenewconnection while utilizing mysql_pconnect , the capability would initially attempt to see as a (tenacious) connect that is as of now open with a similar host, username and secret key. In the event that one is found, an identifier for it will be returned as opposed to opening another association... the association with the SQL server won't be shut when the execution of the content finishes. All things considered, the connection will stay open for sometime later.
Q13. What are the various kinds of blunders in PHP ?
Ans: Here are three essential sorts of runtime blunders in PHP:
Takes note: These are insignificant, non-basic blunders that PHP experiences while executing a content - for instance, getting to a variable that has not yet been characterized. Of course, such mistakes are not shown to the client by any stretch of the imagination - despite the fact that you can change this default conduct.
Alerts: These are more serious mistakes - for instance, endeavoring to incorporate() a record which doesn't exist. Naturally, these blunders are shown to the client, however they don't bring about script end.
Lethal mistakes: These are basic blunders - for instance, launching an object of a non-existent class, or calling a non-existent capability. These blunders cause the prompt end of the content, and PHP's default conduct is to show them to the client when they happen.
Q14. What is PEAR?
Ans: PEAR is a structure and conveyance framework for reusable PHP components.The project tries to give an organized library of code, keep a framework for disseminating code and for overseeing code bundles, and advance a standard coding style.PEAR is broken into three classes: PEAR Core Components, PEAR Packages, and PECL Packages. The Core Components incorporate the base classes of PEAR and PEAR_Error, alongside data set, HTTP, logging, and messaging capabilities. The PEAR Packages incorporate usefulness accommodating confirmation, systems administration, and document framework highlights, as well as devices for working with XML and HTML layouts.
Q15. Recognize urlencode and urldecode?
Ans: This technique is best when encode a string to utilized in a question part of a url. it returns a string in which all non-alphanumeric characters with the exception of - _. have replece with a percentege(%) sign . the urldecode->Decodes url to encode string as any %and other symbole are decipher by the utilization of the urldecode() capability.
Q16. How might we expand the execution season of a PHP script?
Default time considered the PHP contents to execute is 30 secs referenced in the php.ini record. The capability utilized is set_time_limit(int sec). Assuming the worth passed is '0', it requires limitless investment. It ought to be noticed that assuming the default clock is set to 30 sec, and 20 sec is determined in set_time_limit(), the content will run for 45 seconds.
This time can be expanded by adjusting the max_execution_time in secs. The time should be changed keeping the climate of the server. This is on the grounds that changing the execution time will influence every one of the locales facilitated by the server.
The content execution time can be expanded by
>Utilizing rest() capability in PHP script
>Utilizing set_time_limit() capability
>As far as possible is 30 seconds. As far as possible can be set to zero to force no time breaking point to stop.
Q17. What is the motivation behind php.ini record?
Ans: The PHP setup record, php.ini, is the last and most prompt method for influencing PHP's usefulness. The php.ini record is perused each time PHP is initialized.in different words, at whatever point httpd is restarted for the module rendition or with each content execution for the CGI variant. In the event that your change isn.t appearing, make sure to pause and restart httpd. Assuming it still isn.t appearing, use phpinfo() to actually look at the way to php.ini.
Q18. What do you mean by having PHP as whitespace obtuse?
Ans: Whitespace is the stuff you type that is normally undetectable on the screen, including spaces, tabs, and carriage returns (end-of-line characters). PHP whitespace harsh implies that it never matters the number of whitespace characters you have in a row.one whitespace character is equivalent to many such characters.
Q19. What are the qualities of PHP factors?
Ans: Here are the main things to be familiar with factors in PHP.
All factors in PHP are meant with a main dollar sign ($).
The worth of a variable is the worth of its latest task.
Factors are doled out with the = administrator, with the variable on the left-hand side and the articulation to be assessed on the right.
Factors can, yet needn't bother with, to be announced before task.
Factors in PHP don't have characteristic sorts - a variable doesn't be aware ahead of time whether putting away a number or a series of characters will be utilized.
Factors utilized before they are appointed have default values.
PHP works effectively of consequently switching types starting with one over completely then onto the next when vital.
PHP factors are Perl-like.
Q20. What are the various kinds of PHP factors?
Ans: PHP has a sum of eight information types which we use to develop our factors −
Numbers − are entire numbers, without a decimal point, as 4195.
Copies − are drifting point numbers, as 3.14159 or 49.1.
Booleans − have just two potential qualities either obvious or misleading.
Invalid − is an exceptional sort that just has one worth: NULL.
Strings − are arrangements of characters, as 'PHP upholds string activities.'
Exhibits − are named and ordered assortments of different qualities.
Objects − are occasions of developer characterized classes, which can bundle up both different sorts of values and works that are well defined for the class.
Assets − are extraordinary factors that hold references to assets outer to PHP (like data set associations).
Q21. How might you characterize a consistent in PHP?
Ans: To characterize a consistent you need to utilize characterize() capability and to recover the worth of a steady, you need to just determining its name. Dissimilar to with factors, you don't have to have a steady with a $.
Q22. What are the distinctions between PHP constants and factors?
There is compelling reason need to compose a dollar sign ($) before a steady, where as in Variable one needs to compose a dollar sign.
Constants can't be characterized by straightforward task, they may just be characterized utilizing the characterize() capability.
Constants might be characterized and gotten to anyplace regardless of variable perusing rules.
When the Constants have been set, may not be re-imagined or indistinct.
Q23. What is the reason for _CLASS_ consistent?
Ans: _CLASS_ − The class name. (Included PHP 4.3.0) As of PHP 5 this consistent returns the class name as it was proclaimed (case-delicate). In PHP 4 its worth is dependably lowercased.
Q24. How might you divert a page utilizing PHP?
Ans: The PHP header() capability supplies crude HTTP headers to the program and can be utilized to divert it to another area. The redirection content ought to be at the actual top of the page to forestall some other piece of the page from stacking. The objective is indicated by the Location: header as the contention to the header() capability. Subsequent to calling this capability the leave() capability can be utilized to end parsing of rest of the code.
Q25. How might we execute a PHP script utilizing order line?
Just run the PHP CLI (Command Line Interface) program and give the PHP script record name as the order line contention. For instance, "php myScript.php", expecting "php" is the order to conjure the CLI program.
Recall that assuming your PHP script was composed for the Web CGI interface, it may not execute as expected in order line climate.
Q26. What is htaccess? For what reason do we utilize this and where?
htaccess documents are setup records of Apache Server that give a method for making design changes on a for each index premise. A record, containing at least one design mandates, is put in a specific report catalog, and the orders apply to that registry, and all subdirectories thereof.
These .htaccess documents are utilized to change the usefulness and highlights of Apache web server.
For example, htaccess document is utilized for url modify.
-> It is utilized to make the site secret key secured.
-> .htaccess record can confine some ip addresses so that on limited ip addresses, the site won't open.
Q27. What is the purpse $_REQUEST variable?
Ans: The PHP $_REQUEST variable contains the items in both $_GET, $_POST, and $_COOKIE. We will examine $_COOKIE variable when we will make sense of about treats. The PHP $_REQUEST variable can be utilized to obtain the outcome from structure information sent with both the GET and POST strategies.
Q28. How might you begin a meeting in PHP?
Ans: A PHP meeting is effortlessly begun by settling on a decision to the session_start() function.This capability first checks in the event that a meeting is now begun and in the event that none is begun, it begins one. It is prescribed to put the call to session_start() toward the start of the page.
Q29. What is capability abrogating?
Ans: Function definitions in youngster classes abrogate definitions with a similar name in parent classes. In a youngster class, we can change the meaning of a capability acquired from parent class.
Q30. What are connection points in PHP?
Ans: Interfaces are characterized to give a typical capability names to the practitioners. Different practitioners can execute those points of interaction as per their prerequisites. You can say, points of interaction are skeltons which are executed by designers.
Q31. What is the really utilized PHP form?
Ans: Version 5 is the really utilized rendition of PHP.