Last active
August 29, 2015 14:07
-
-
Save Lambdanaut/d980fb47e66a1a6dbd9b to your computer and use it in GitHub Desktop.
PHP Candidate interview questions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Q | |
| CSS: | |
| Explain the difference between visibility:hidden; and display:none; | |
| ## A | |
| Visibility:Hidden; - It is not visible but takes up it's original space. | |
| Display:None; - It is hidden and takes up absolutely no space as if it was never there. | |
| ## Q | |
| What does `git add .` accomplish? | |
| ## A | |
| It stages all files in the current working directory and below to be committed. | |
| ## Q | |
| What does the `ls -l` command accomplish? | |
| ## A | |
| Displays a list of files/directories in the current working directory, as well as | |
| * The rwx permissions for the file | |
| * The owner of the file | |
| * The size of the file | |
| * The date they were last edited | |
| ## Q | |
| What is the value of $x? | |
| function doIt (&$y) { | |
| $y .= "martian"; | |
| } | |
| $x = "invaders "; | |
| doIt($x); | |
| ## A | |
| "invaders martian" | |
| ## Q | |
| Which of the following is more efficient? | |
| $abc = 'Hello, world! '; | |
| $xyz = "Hello, world! "; | |
| Why? | |
| ## A | |
| $abc | |
| $xyz has to parse the string for variable interpolation. | |
| ## Q | |
| What is the value of $a? | |
| $a = 42 ? "This is the value" : "No, THIS is the value!"; | |
| ## A | |
| $a = "This is the value" | |
| ## Q | |
| What is the value of $a, $b, and $c? | |
| $a = 10 == "10"; | |
| $b = $a + true; | |
| $c = $b + "2"; | |
| ## A | |
| $a == true (or 1) | |
| $b == 2 | |
| $c == 4 | |
| ## Q | |
| What will the following code echo out? | |
| if (strpos('abcdefg','abc')){ | |
| echo "found it!"; | |
| } else { | |
| echo "didn't find it.."; | |
| } | |
| Followup: How could you change the code so that it returns "found it!" if "abc" is within the given string? | |
| ## A | |
| a. "didn't find it.." because strpos evaluates to `0`, which is false. | |
| b. | |
| if (strpos('abcdefg','abc') !== false){ | |
| echo "found it!"; | |
| } else { | |
| echo "didn't find it.."; | |
| } | |
| ## Q | |
| What is wrong with this statement? | |
| ` SELECT * FROM table WHERE id = $_POST[ 'id' ] ` | |
| ## A | |
| It is vulnerable to SQL injection. Never use user input directly in queries. Sanitize it first. Preferably use prepared statements (PDO) 2. Don't select all columns (*), but specify every single column. This is predominantly meant to prevent queries hogging up memory when for instance a BLOB column is added at some point in the future. | |
| ## Q | |
| Given this code: | |
| function doSomething( &$arg ) | |
| { | |
| $return = $arg; | |
| $arg += 1; | |
| return $return; | |
| } | |
| $a = 3; | |
| $b = doSomething( $a ); | |
| ...what is the value of $a and $b after the function call and why? | |
| ## A | |
| $a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the return value of the function is a copy of (not a reference to) the initial value of the argument. | |
| ## Q | |
| What is the difference between public, protected and private in a class definition? | |
| ## A | |
| public makes a class member available to "everyone", protected makes the class member available to only itself and derived classes, private makes the class member only available to the class itself. | |
| ## Q | |
| http://qntm.org/bulbs | |
| ## A | |
| Answer: 14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment