The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.
PHP Interviews are getting tough these days as the technology grows faster. To get through the PHP interview one needs to update him/herself in a regular manner. Having said that, just before the interview, it is very important to have a quick glance of the reputed PHP questions and answers to make yourself comfortable during the interview process. This is where DoAnswers.com helps you in renewing yourself on PHP and various other technologies interview preparation.
11. I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what?s the problem?
PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.
12. If the variable $a is equal to 5 and variable $b is equal to character a, what?s the value of $$b?
100, it?s a reference to existing variable.
13. What does a special set of tags do in PHP?
The output is displayed directly to the browser.
14. What is the difference between characters \023 and \x23?
The first one is octal 23, the second is hex 23.
15. What will work faster? Code sample 1:
$var 3 = $var1.$var2; Or code sample 2: $var3 = "$var1$var2"; Both examples would provide the same result $var3 equal to "Welcome to TechInterviews.com". However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.
16. What's the difference between accessing a class method via -> and via ::?
:: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.
17. What's the difference between htmlentities() and htmlspecialchars()?
htmlspecialchars only takes care of <, >, single quote ?, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
18. What's the difference between include and require?
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.
19. What's the difference between md5(), crc32() and sha1() crypto on PHP?
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. So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?Answer:Crypto usage in PHP is simple, but that doesn?t mean it?s free. First off, depending on the data that you?re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.
20. What's the special meaning of __sleep and __wakeup?
__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.