Вы находитесь на странице: 1из 3

PHP Design Patterns PHP Job Interview Questions As a PHP contractor, consultant, and freelancer I've had a fair

number of interviews - and sometimes I have been asked technical questions. Here are a few to help you prepare for your next PHP job interview. =,==,=== - what is the difference between these? = assigns a value, == checks if value is the same, === checks if value is the same and the variables are of the exact same type. Echo, print, printf - what is the difference between these? Print and echo both output what is passed to them. Print acts like a function, so you can use it in complex statements. Printf is used to format the output. Include, include once, require - what is the difference between these? Include will includes a file each time it is called. Include_once would only include a file one time, so if a php program has a file in two include_once statements only the first will be done. Requre is like include, but if the file included is not available a fatal error occurs and processing stops. Are variables passed to functions by reference or value? A variable is passed by value unless the variable is passed with an &, such as functionName(&$variableName) How do you encrypt data? The PHP crypt() function can be used to encrypt data. The PHP md5() function is very pretty widely used, but is a one way hash, and can not be decrypted. (Honestly, the one time I had this question I drew a complete blank, so I'm not exactly certain what they were looking for.) What editor or ide do you use? Interesting question, probably does say something about your programming capabilites. I use Eclipse with PHP extensions, and interviewers seem to like that. There are probably others such as Zend Studio that are also excellent answers. Serious Unix users would be good with vi or emacs. PHP Statics, what are they and how do you use them? As with Java, if the job is for OO PHP (that is PHP 5), there will be a question on PHP static variables. You may be asked how to reference a static from inside and outside of the class it is in, or just show that you get the basic concept of a variable or function that is for the whole class and not an instance.

Design Patterns general questions Now we are really into OO stuff. As in java job interviews I've usually been asked about design patterns in fairly vague terms, such as "describe the design patterns used in the systems you have worked on". I was asked that so much that I drew out some UML to bring with me to interviews, as I found drawing up the UML during the interview to be distracting and slow. What does a special set of tags <?= and ?> do in PHP? The output is displayed directly to the browser. Whats the difference between include and require? Its 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. I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, whats the problem? - PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems. Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example? In this example it wouldnt matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces. How do you define a constant? Via define() directive, like define ("MYCONSTANT", 100); How do you pass a variable by value? Just like in C++, put an ampersand in front of it, like $a = &$b Will comparison of string "10" and integer 11 work in PHP? Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared. When are you supposed to use endif to end the conditional statement? When the original if was followed by : and then the code block without braces.

Explain the ternary conditional operator in PHP? Expression preceding the ? is evaluated, if its true, then the expression preceding the : is executed, otherwise, the expression following : is executed How do I find out the number of parameters passed into function? func_num_args() function returns the number of parameters passed in. Whats 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. Are objects passed by value or by reference? Everything is passed by value. How do you call a constructor for a parent class? parent::constructor($value) Whats the special meaning of __sleep and __wakeup? __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them. Why doesnt the following code print the newline properly? <?php $str = Hello, there.nHow are you?nThanks for visiting TechInterviews; print $str; ?> Because inside the single quotes the n character is not interpreted as newline, just as a sequence of two characters - and n. What is the difference between characters 23 and x23? The first one is octal 23, the second is hex 23. How do you match the character ^ at the beginning of the string? ^^

Вам также может понравиться