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.
1. Are objects passed by value or by reference?
Everything is passed by value.
2. Explain the ternary conditional operator in PHP?
Expression preceding the ? is evaluated, if it?s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.
3. For printing out strings, there are echo, print and printf. Explain the differences.
echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like: and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it?s the slowest way to print out data out of echo, print and printf.
4. How come the code works, but doesn?t for two-dimensional array of mine?
Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would?ve worked.
5. How do I accomplish that with PHP?
On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().
6. How do I find out the number of parameters passed into function?
func_num_args() function returns the number of parameters passed in.
7. How do you call a constructor for a parent class?
parent::constructor($value)
8. How do you define a constant?
Via define() directive, like define ("MYCONSTANT", 100);
9. How do you match the character ^ at the beginning of the string?
^\^
10. How do you pass a variable by value?
Just like in C++, put an ampersand in front of it, like $a = &$b