The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 Thank you for all your feedback It's really helpful, and thanks for spell checking I think I got everyone's suggestions and fixed them! Well, I have re-worded many of the questions and replaced the "non-beginner" ones with jesirose's suggestion of "find/fix the error" questions and also fill in the blank. === 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 (not property)? - var $var = 0; * $_ = 0; - $1 = 0; - $var:int = 0; 4. Which line will throw a syntax error? <?php $array = array(1,2,3); foreach($var in $array){ echo $var; } ?> - 1 - 2 * 3 - 4 - 5 - 6 5. Which loop type is 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 printing 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. Fill in the blank: <?php ______($_GET["year"]){ case 2000: case 2001: echo "2000 or 2001!"; break; case 2012: case 2013: echo "2012 or 2013!"; break; default: echo "Bad Date!"; break; } ?> - if - define - while * switch - declare 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 of a 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 * Assigns a key to its value in an array - A comparison operator "equal to or greater than" - Both B and C 20. What does "->" (without the quotes) signify? * An operator that calls 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 continues the 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 missing? <?php $_SESSION["name"] = "Billy Joe"; echo $_SESSION["name"]; ?> - $_SESSION = new Session(); * session_start(); - header("Content-Type: text/html"); - define("$_SESSION", array()); 24. Does '"null" == null' evaluate to true or false? - True * False 25. How do you escape quotes within 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>"; Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378708 Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 I like the new ones you added. Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378710 Share on other sites More sharing options...
kicken Posted September 17, 2012 Share Posted September 17, 2012 17. When php reads functions with functions as parameters it reads: - From left to right - From right to left * From the middle out I still don't like that one. It still could be interpreted in either way. Perhaps a better phrased question would be "In what order are nested function calls evaluated?" with just two options "Inner most first" or "outer most first" (or you could use left to right/right to left, but drop middle out). I also still don't much care for the wording of #5 or #7. For #5 perhaps use 'lists' or 'collections' instead of arrays. For #7 either remove option B or specify in the question PHP v5.4 (or drop the 'and lower' part from the beginning of your quiz). Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378718 Share on other sites More sharing options...
The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 I like the new ones you added. Thank you! New #17: 17. In what order are nested function calls evaluated? - Outer most function first * Inner most function first I dropped the "and lower" its php 5.4.x now How about this (I don't quite like "lists" or "collections"? 5. Which loop type is best used for arrays? - do ... while * foreach - while - for Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378725 Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 Call it a control structure, not a "loop type" and maybe say "used for iterating through an array". Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378727 Share on other sites More sharing options...
The Little Guy Posted September 17, 2012 Author Share Posted September 17, 2012 I like that one. I moved it to an online text file. http://ryannaddy.com/PHP%20Beginner.txt Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378728 Share on other sites More sharing options...
scootstah Posted September 18, 2012 Share Posted September 18, 2012 23. What is missing? <?php $_SESSION["name"] = "Billy Joe"; echo $_SESSION["name"]; ?> - $_SESSION = new Session(); * session_start(); - header("Content-Type: text/html"); - define("$_SESSION", array()); I don't really like that. The code will run and work fine as it stands, except it won't be a real session. Plus, it's not immediately obvious that this snippet of code is actually the start of an application. Maybe I'm just nitpicking now. Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378798 Share on other sites More sharing options...
KevinM1 Posted September 18, 2012 Share Posted September 18, 2012 23. What is missing? <?php $_SESSION["name"] = "Billy Joe"; echo $_SESSION["name"]; ?> - $_SESSION = new Session(); * session_start(); - header("Content-Type: text/html"); - define("$_SESSION", array()); I don't really like that. The code will run and work fine as it stands, except it won't be a real session. Plus, it's not immediately obvious that this snippet of code is actually the start of an application. Maybe I'm just nitpicking now. I think it's a fair crit. Given how easy (and ubiquitous) it is to enter/exit PHP, it's hard to tell if that snippet is an entire script or if we're seeing code that's in medias res within a larger script. Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378942 Share on other sites More sharing options...
Mahngiel Posted September 18, 2012 Share Posted September 18, 2012 Q: What is the visibility of this class function: function set_name(){} * public Q: Who / What can access private properties or methods? * only the class itself Q: Who / What can access protected properties or methods? * Class itself, parents, children Q: Who / What can access public properties or methods? * Everybody :yay: Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1378967 Share on other sites More sharing options...
KevinM1 Posted September 18, 2012 Share Posted September 18, 2012 Q: Who / What can access protected properties or methods? * Class itself, parents, children This should just be "Class itself and its children." Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379028 Share on other sites More sharing options...
Mahngiel Posted September 18, 2012 Share Posted September 18, 2012 Q: Who / What can access protected properties or methods? * Class itself, parents, children This should just be "Class itself and its children." http://php.net/manual/en/language.oop5.visibility.php Members declared protected can be accessed only within the class itself and by inherited and parent classes Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379041 Share on other sites More sharing options...
The Little Guy Posted September 18, 2012 Author Share Posted September 18, 2012 I have testing up for the "Beginner" test, so if you wanna give it a try, here is the link: http://phpsnips.com/test.php Eventually it will require a login, so scores can be saved to a profile, but none of that is in place atm, just the test and the percent correct at the end. @Mahngiel, Thanks for the questions, I will probably use those in the "Advanced" Test. Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379045 Share on other sites More sharing options...
scootstah Posted September 18, 2012 Share Posted September 18, 2012 I think "Comparisons can be passed as parameters to a function" should say "Expressions can be . . ." Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379046 Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 On # 11 I would add parens on the answer. Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379050 Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 88%?? wtf. I want to see what I got wrong. :-P Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379052 Share on other sites More sharing options...
The Little Guy Posted September 18, 2012 Author Share Posted September 18, 2012 On # 11 I would add parens on the answer. I don't know what #11 is, the questions are displayed in a random order Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379059 Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 The one about ternary operator Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379062 Share on other sites More sharing options...
Philip Posted September 18, 2012 Share Posted September 18, 2012 $color = $i == 2 ? "red" : "blue"; should read: $color = ($i == 2) ? "red" : "blue"; Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379067 Share on other sites More sharing options...
Philip Posted September 18, 2012 Share Posted September 18, 2012 And I agree. You already know what the answers are / weren't, so why not show us what we missed to learn? Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379068 Share on other sites More sharing options...
The Little Guy Posted September 18, 2012 Author Share Posted September 18, 2012 And I agree. You already know what the answers are / weren't, so why not show us what we missed to learn? I was working on that. Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379075 Share on other sites More sharing options...
KevinM1 Posted September 18, 2012 Share Posted September 18, 2012 Q: Who / What can access protected properties or methods? * Class itself, parents, children This should just be "Class itself and its children." http://php.net/manual/en/language.oop5.visibility.php Members declared protected can be accessed only within the class itself and by inherited and parent classes Huh. That's odd, as generally one wouldn't ever need to have a parent access a child's protected member (okay, that sounds dirty). The whole point of protected is to say "From this point on in the class hierarchy, only me and my children can see this." Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379079 Share on other sites More sharing options...
scootstah Posted September 18, 2012 Share Posted September 18, 2012 Q: Who / What can access protected properties or methods? * Class itself, parents, children This should just be "Class itself and its children." http://php.net/manual/en/language.oop5.visibility.php Members declared protected can be accessed only within the class itself and by inherited and parent classes Huh. That's odd, as generally one wouldn't ever need to have a parent access a child's protected member (okay, that sounds dirty). The whole point of protected is to say "From this point on in the class hierarchy, only me and my children can see this." Yeah, that sounds literally ass-backwards. Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379120 Share on other sites More sharing options...
Hall of Famer Posted September 19, 2012 Share Posted September 19, 2012 Which of the following OOP feature is not yet supported as of PHP 5.4? A. Abstract Class B. Inner/Nested Class C. Interface D. Namespace E. Trait And the answer is... Well we all know what it is. XD Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379174 Share on other sites More sharing options...
xylex Posted September 19, 2012 Share Posted September 19, 2012 wrong topic Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1379333 Share on other sites More sharing options...
Barand Posted September 24, 2012 Share Posted September 24, 2012 BTW this code is valid (note no semicolon) <?php echo 'Hello world' ?> Quote Link to comment https://forums.phpfreaks.com/topic/268447-php-test-questions/page/2/#findComment-1380716 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.