PHP interview questions and answers

Q.1  What type of inheritance that php supports?.

Ans:  PHP supports only single inheritance.But multiple inheritance can be implemented in php through use of interface.



Q.2  What’s the special meaning of __sleep and __wakeup?

Ans:   __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

 

Q.3  Would you initialize your strings with single quotes or double quotes?

Ans:   Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

 

 Q.4  How come the code <?php print "Contents: $arr[1]"; ?> works, but <?php print "Contents: $arr[1] [2]"; ?> doesn’t for two-dimensional array of mine?

Ans:  Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.


 

Q.5  What is the difference between echo and print?

Ans: 
echo:
    Is a command only.
    Faster than print
print:

    Is a function.
    It will return true(1) or false(0) or some values.




Q.6  POST and GET Methods : Which will execute faster POST or GET? Explain?

Ans:  Once most important difference is when you are sending the form with GET method. It displays name/value pair used in the form at the address bar of the browser preceded by url.Whereas if you send the form with POST method then user can not see that information and Secondly When you want to send short or small data & Less Sensitive Data then you can use GET Method. But for long data & Sensitive Data sending say more then 100 character you can use POST method

 

 

Q.7  What’s the difference between htmlentities() and htmlspecialchars()?

Ans:  htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand.
htmlentities translates all occurrences of character sequences that have different meaning in HTML.

 

 

Q.8  How do you define a constant?

Ans:  Via define() directive, like define ("MYCONSTANT", 100);

 

 

Q.9  Explain the ternary conditional operator in PHP?

Ans: Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.

 

 

Q.10  What does a special set of tags <?= and ?> do in PHP?

Ans:  The output is displayed directly to the browser.

 

 

Q.11  What’s the difference between include and require?

Ans:  It’s how they handle failures. 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.

 

 

Q.12  How do you pass a variable by value?

Ans:  Just like in C++, put an ampersand in front of it, like $a = &$b

 

 

Q.13 Difference between require() and include()?

Ans:  if filepath not found .. require() teriminates the program and gives fatal error but include() not teriminate the program it gives warning msg and continues to program.

 

 

Q.14  What are cron jobs? Explain in details. ?

Ans:  CRON is the name of program that enables UNIX users to execute commands or
scripts (groups of commands) automatically at a specified time/date. It is
normally used for sys admin commands like makewhatis which builds a search
database for the man -k command or for running a backup script but can be used
for anything. A common use for it today is connecting to the internet and
downloading your email.

 

 

Q.15  What is the diffrence between Notify URL and Return URL?.

Ans:  Notify URL: The URL to which PayPal posts information about the transaction via Instant Payment Notification. Must be URL-encoded. Its an optional field have maximum 256 characters length.


 

 

Q.16  How do I find out the number of parameters passed into function?

Ans:  func_num_args() function returns the number of parameters passed in.

 

 

Q.17  what are the various methods to pass data from one web page to another web page ?

Ans: 
1.POST
2.GET
3.SESSION
4.COOKIES
5.QUERY STRING

 

 

Q.18  Will comparison of string "10" and integer 11 work in PHP?

Ans:  Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.

 

 

Q.19  What is differenc between mysql_connect and mysql_pconnect?

Ans:  mysql_connect opens up a database connection every time a page is loaded. mysql_pconnect opens up a connection, and keeps it open across multiple requests. mysql_pconnect uses less resources, because it does not need to establish a database connection every time a page is loaded.

 

 

Q.20  How do you call a constructor for a parent class?

Ans:  parent::constructor($value)

 

 

Q.21  When are you supposed to use endif to end the conditional statement?

Ans:  When the original if was followed by : and then the code block without braces.

 

 

Q.22  What’s the difference between md5(), crc32() and sha1() crypto on PHP?

Ans:  The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

 

 

Q.23  What is htaccess? Why do we use this and Where?

Ans:  .htaccess files are configuration files of Apache Server which provide a 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.

 

 

Q.24  What is the difference between characters 23 and x23?

Ans:  The first one is octal 23, the second is hex 23.

 

 

Q.25  How do you know (status) whether the recipent of your mail had opened the mail i.e read the mail?

Ans:  In PHP we can use "Disposition-Notification-To:" in header function. 

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Hostgator Coupon Code