The Little Guy Posted September 16, 2012 Share Posted September 16, 2012 I am going to be making tests for my site, right now I am building a list of questions. Does any have any input on some good questions to add? There will be 3 (maybe 4) PHP tests: - Beginner (structure / construct) - Intermediate (functions / classes) - Advanced (not sure atm) - Expert (Maybe) So, if anyone would like to add some questions, please let me know! Quote Link to comment Share on other sites More sharing options...
scootstah Posted September 16, 2012 Share Posted September 16, 2012 You can probably get a ton of ideas here: http://www.reddit.com/r/dailyprogrammer/ Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 You can probably get a ton of ideas here: http://www.reddit.com/r/dailyprogrammer/ This should be added to the list of ideas sticky! Quote Link to comment Share on other sites More sharing options...
spiderwell Posted September 17, 2012 Share Posted September 17, 2012 the ole interpolation Vs concatenation question! do some on variable scopes? ask why you would use recursion? whats the difference between -> and => I am sure theres a lot more! Quote Link to comment Share on other sites More sharing options...
scootstah Posted September 17, 2012 Share Posted September 17, 2012 What is the difference between == and ===? Assuming $var has a value of 1, which statements evaluate to true? [*]$var == true [*]isset($var) [*]empty($var) [*]$var === true Assuming $var has a value of 0, which statements evaluate to true? [*]$var == false [*]isset($var) [*]empty($var) [*]$var === false Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 Thanks for some of the questions, I have used a few of them! Here is one I added, not sure if it is too mean (trick question)... * = correct answer All lines MUST end with a semi-colon? - True * False Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 17, 2012 Share Posted September 17, 2012 Thanks for some of the questions, I have used a few of them! Here is one I added, not sure if it is too mean (trick question)... * = correct answer All lines MUST end with a semi-colon? - True * False The wording could be better. 'Lines' is vague. Do you mean to include comments? Opening/closing PHP tags? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 the question is meant to mean after: - constructs (loops, if/else) - includes - functions - last line of code before ?> Quote Link to comment Share on other sites More sharing options...
scootstah Posted September 17, 2012 Share Posted September 17, 2012 That doesn't really make sense. The obvious answer would be that no, not every line would end in a semi colon. People will get this wrong simply because they will think you mean something else. Change the question to, "All statements MUST end with a semi-colon" Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 Is a control structure a statement? Quote Link to comment Share on other sites More sharing options...
Adam Posted September 17, 2012 Share Posted September 17, 2012 Is a control structure a statement? Nope. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 So I think The Little Guy is trying to include control structures, since, well, his post says that. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 <?php // Valid: while($i<10){} // Valid: echo "hello"; // Invalid: echo "hello" // Valid: for($i=0;$i<2;$i++){; echo "hello"; }; // Valid: echo "hello" ?> Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 17, 2012 Share Posted September 17, 2012 That doesn't really make sense. The obvious answer would be that no, not every line would end in a semi colon. People will get this wrong simply because they will think you mean something else. Agreed. Remember, questions of this caliber are aimed at newbies. Don't ask vague questions, or what you may think are clever trick questions. The whole point is for them to test their knowledge and further their understanding, not engage in trivial pursuit. Quote Link to comment Share on other sites More sharing options...
Adam Posted September 17, 2012 Share Posted September 17, 2012 // Valid: for($i=0;$i<2;$i++){; echo "hello"; }; Fair enough it's valid, but your question was what 'lines MUST end with a semi-colon'. Semi-colons aren't required there, and shouldn't be used there. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 17, 2012 Share Posted September 17, 2012 <?php // Invalid: echo "hello" // Valid: echo "hello" ?> Uh.... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 the ending ?> automatically terminates the line in the second one. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 17, 2012 Share Posted September 17, 2012 the ending ?> automatically terminates the line in the second one. And how would that be useful to a beginner? Really, a question like this does more to prove you know about the details of the language than help a newbie reaffirm they have a grasp of the basics. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 the ending ?> automatically terminates the line in the second one. And how would that be useful to a beginner? Really, a question like this does more to prove you know about the details of the language than help a newbie reaffirm they have a grasp of the basics. I agree. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 Okay, so I came up with 25 questions for the beginners test. Any suggestions on any of these? I would like to try an keep the test 25 - 30 questions long. Thanks for the input! === The following questions are based on php 5.4.x and lower === 1. Assuming $var has a value of 0, which statements evaluate to true? * $var == false - isset($var) - empty($var) - $var === false 2. Which of the following does not belong? - echo "Hello, $first_name"; - echo <<<EOD Hello, $first_name EOD; * cout << "Hello, $first_name"; - print "Hello, $first_name"; 3. Which of the following is a valid variable? - var $var = 0; * $_ = 0; - $1 = 0; - $var:int = 0; 4. What is the output of the following code: for($i = 0; var_dump(100), $i < 10; $i++); - An error - prints "100" 10 times - Nothing * prints "int(100)" 10 times 5. Which loop type is souly intended for arrays? - do ... while * foreach - while - for 6. What is the correct way to define a function? - function myFunction(){} - define function myFunction(){} - function myFunction():void{} - myFunction = function(){}; - Both A and C * Both A and D 7. What is the incorrect way to define an array? - $array = array(); - $array = []; * $array = new Array(); - Both B and C - All of the above 8. Which of the following methods is meant for variable debugging? - echo $my_var; echo $my_var1; - echo gettype($my_var); echo gettype($my_var1); * var_dump($my_var, $my_var1); 9. Which of the following is not a valid comment? * ' This is a comment - # This is a comment - /* This is a comment */ - // This is a comment 10. All statements must end with a semi-colon? * True - False 11. Blank lines out side of php blocks are fine before a header? - True * False 12. What is the value of $a on line 10? <?php $a = 1; function add(){ $b = 6; $a = 5; $a = $a + $b; return $a; } add(); echo $a; ?> - 11 - 6 * 1 - 5 13. What is the final output of this code? <?php $a = "hello"; $$a = "world"; echo "$a $hello"; ?> - hello $hello * hello world - An error ($hello is not defined) - An error (You can not have $$ as a variable) 14. What what does a ternary statement look like? - if($i == 2){ $color = "red"; }else{ $color = "blue" } * $color = $i == 2 ? "red" : "blue"; - if($i == 2) $color = "red"; else $color = "blue"; 15. What does Modulus do? - Returns the value after the decimal after division * Returns the remainder ofa value after division - Just another way to divide two numbers - Returns the value before the decimal after division 16. What does 3 equal signs mean when comparing values? * Values must be the same value and same type - 3 equal signs is an error - 3 equal signs is the same as 2 17. When php reads functions with functions as parameters it reads: - From left to right - From right to left * From the middle out 18. Comparisons can be passed as parameters to a function? * True - False 19. What does "=>" (without the quotes) signify? - A pointer that points to a method/property in an object * A pointer that points a key to its value from an array - A comparison operator "eqal to or greater than" - Both B and C 20. What does "->" (without the quotes) signiy? * A pointer that points to a method/property in an object - A pointer that points a key to its value from an array - A comparison operator "greater than zero" - Both B and C 21. What is the difference between "break" and "continue" within a loop? - break exits a loop and ends execution of the file; continue exits a loop and continues file execution - break pauses code execution for a short period; continue does not pause code execution * break exits a loop and continues; continue, continues at the beginning of the loop - both break and continue exit a loop and continue code execution 22. What does "goto" do? * Allows you to tell php to goto a particular label - Allows you to tell php to goto a particular line number - Allows you to tell php to goto a file for execution 23. What is the output on line 8? <?php function foo($x){ return function($y) use ($x){ return $y + $x; }; } $a1 = foo(10); echo $a1(2); ?> - 2 - 10 * 12 - 0 24. What is an Anonymous function? * A function that has no name - A function that is sometimes a function - A function that is also a vaiable - A function who's name is anonymous (function anonymous(){}) 25. How do you escape quotes withing quotes? - echo "<a href=/"http://phpsnips.com/">PHP Snips</a>"; - echo '<a href="http://phpsnips.com">PHP Snips</a>'; * echo "<a href=\"http://phpsnips.com\">PHP Snips</a>"; - echo "<a href="http://phpsnips.com">PHP Snips</a>"; Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 #4 I have never seen someone use that syntax, and there is little if anything in the manual that indicates how it can be used. Not beginner material. See Kevin's point above. #5 - solely not souly. #10 - see above. #13 - also not beginner material. #15 - maybe include the % not just the name. #16 - see 15 17 - I don't even understand what you're asking, and if I do understand it's not even a sensible question. 19 - equal 23&24 - not beginner material What would be useful is "find the error" questions (show code and ask to find lines with errors, without giving the PHP generated error), as well as "fix the error" (given a syntax error, fix the code). Include logical errors not just code errors. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted September 17, 2012 Share Posted September 17, 2012 This: 1. Assuming $var has a value of 0, which statements evaluate to true? * $var == false - isset($var) - empty($var) - $var === false Is wrong. Isset will evaluate to true since 0 !== null. Empty will evaluate to true since 0 is considered the same as empty. Also, neither -> nor => are pointers. At all. -> is the to member operator. => is essentially an indexer. Pointer has a very specific meaning, one which is never used in PHP itself since we cannot ever touch dynamic memory. Quote Link to comment Share on other sites More sharing options...
Philip Posted September 17, 2012 Share Posted September 17, 2012 I could see #3.1 being argued as correct as it is the definition of a class property (which arguably is a variable in its own.) #11 probably needs clarification, like "before printing a header" #15.2 needs a space between "of" and "a" #21.3 needs clarification on what it continues IMO Is 23/24 really a beginners question? Plus all of the above comments Quote Link to comment Share on other sites More sharing options...
kicken Posted September 17, 2012 Share Posted September 17, 2012 (others beat me to some of these but here ya go anyway) 1. Assuming $var has a value of 0, which statements evaluate to true? * $var == false - isset($var) - empty($var) - $var === false empty($var) would be true as well. 3. Which of the following is a valid variable? - var $var = 0; * $_ = 0; - $1 = 0; - $var:int = 0; var $var=0; is technically valid, depending on how picky you want to get: class Blah { var $var = 0; public function Blah(){ var_dump($this->var); } } 5. Which loop type is souly intended for arrays? - do ... while * foreach - while - for No true. You can use foreach on objects, and it is intended as well (See the Iterator interface); 6. What is the correct way to define a function? - function myFunction(){} - define function myFunction(){} - function myFunction():void{} - myFunction = function(){}; - Both A and C * Both A and D D should be $myFunction = function(){}; 7. What is the incorrect way to define an array? - $array = array(); - $array = []; * $array = new Array(); - Both B and C - All of the above This depends on what version your looking at. $array=[]; is valid in php 5.4 only (your "5.4.x and lower" implies covering 5.3 and 5.2). There are still plenty of people not using that version. 17. When php reads functions with functions as parameters it reads: - From left to right - From right to left * From the middle out This could be mis-interpreted. I assuming you mean that if you do something like: func(anotherfunc($a, $b)); php will first execute anotherfunc, then func. An alternate meaning for that question though would be given this line: func($a, $a++, $b, $c+30); in what order are the parameters run? The answer to that is left-to-right. [code 21. What is the difference between "break" and "continue" within a loop? - break exits a loop and ends execution of the file; continue exits a loop and continues file execution - break pauses code execution for a short period; continue does not pause code execution * break exits a loop and continues; continue, continues at the beginning of the loop - both break and continue exit a loop and continue code execution [/code] I would change the wording on that answer so you don't use 'continue' so much. Perhaps something like ""break" exists the loop and continues script execution; "continue" jumps immediately to the next iteration of the loop." ----- You have various spelling errors in some questions too, so do a proof-read. Quote Link to comment Share on other sites More sharing options...
scootstah Posted September 17, 2012 Share Posted September 17, 2012 3. Which of the following is a valid variable? - var $var = 0; * $_ = 0; Technically, var $var = 0; is valid for class variables. 5. Which loop type is souly intended for arrays? * foreach Foreach also works with objects. 6. What is the correct way to define a function? - myFunction = function(){}; Ehhhhhhh. I don't know about this one. It's not strictly about defining a function. But, I digress. 7. What is the incorrect way to define an array? - $array = []; This is only valid for PHP >= 5.4, so it might confuse some beginners. 8. Which of the following methods is meant for variable debugging? - echo $my_var; echo $my_var1; - echo gettype($my_var); echo gettype($my_var1); * var_dump($my_var, $my_var1); I'm not sure var_dump() is meant for debugging. It is helpful, sure. echo's can be just as helpful, depending on the situation. Other things like print_r or var_export() can be useful as well. 21. What is the difference between "break" and "continue" within a loop? * break exits a loop and continues; continue, continues at the beginning of the loop This is a little vague if not inaccurate. break exits from a loop at the current iteration and proceeds through the rest of the code. continue breaks from a loop at the current iteration, and begins the next iteration. EDIT: Damn, kicken beat me on a few of these. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.