jump to content

Examination Questions

PHP history and uses

  • Who invented PHP?
  • What major versions of PHP have been released. List some major changes/additions in each version.
  • What does the acronym LAMP mean?
  • On what platforms does PHP run?
  • List at least 5 other server side technologies comparable to PHP.
  • What is Open Source? What does it mean that PHP is Open Source?

Installation and basic configuration

  • Where can you find information about PHP and/or help in solving problems?
  • When installing PHP, describe some differences you should have between a developers’ installation and a production server.
  • Explain the concepts of development, staging and production servers.

Basic PHP syntax

  • Describe the various kind of errors in PHP and how they should be handled on a production server.
  • What is a module in PHP? Name at least 5 modules.
  • What tags are there to mark up blocks of PHP code? Which one is preferred and why?
  • Explain what happens when you omit the closing php tag on a page, and why that often is preferable

PHP best practices overview

  • Describe the key characteristics of a well written PHP-application.
  • What is a coding convention? List a few features of the PEAR coding standard.
  • What is revision control? Name at least 3 well known version control systems.
  • What does the following PhpDoc tags mean: @author, @package, @filesource, @param, @return?
  • What is a bug tracker? Name at least 3 well known bug trackers.

Programming concepts

  • What characters are allowed in identifier names? What characters are they allowed to begin with?
  • Explain how the operators =, == and === work.
  • What is the value of: “5 needles” + “1 haystack”? Explain how type conversion occurs.
  • What is the value of: 3 * 2 . ” things” (note the space after 2)? Explain how type conversion occurs.
  • What is the difference between assignment by value and assignment by reference? When does the latter occur by default? How do one specify it manually?
  • Explain what an unary, binary and ternary operator is.
  • PHP 5.3 introduced a short form for the ternary operator, explain how it works.
  • Write at least 5 complex expressions involving different types of operators and values and explain how they are evaluated according to their precedence and associativity.
  • What is the differeence between $foo = null and unset($foo)?
  • Besides false, what values evaluates as false, when used in a boolean way (falsy values)?
  • Define a constant called FOO that will have the value I’m Foo, not Bar’.
  • Write a single statement that assigns a value to several variables, and explain how it demonstrates associativity.
  • What is a parameter to a function?
  • How do you set default values to function parameters?
  • List a few common guidelines for good function design.
  • Explain the difference between passing parameters by value or passing parameters by reference.
  • What is call time pass by reference? Why should it be avoided?
  • What is a static variable in a function?
  • What scope do variables have in functions by default?
  • How can one access global variables from a function? List 3 ways and compare their benefits and drawbacks.

HTTP

  • What are the 3 most common HTTP methods?
  • What is MIME?
  • Set a MIME header for a JPEG-image, using a PHP command.

Character encoding

  • What is internationalization and localization?
  • What is a character encoding?
  • What is the default character encoding in PHP 5?
  • Briefly explain the terms glyph, character, encoding and font as they are used in Unicode.
  • What is a single byte character encoding? Give a few examples.
  • What is a multi byte character encoding? Give a few examples.
  • How is character encoding specified in an HTTP header?
  • Explain the benefits of UTF-8 compared to older encodings.
  • What is an ASCII compatible encoding? Name two such encodings.
  • How can one convert a string between UTF-8 and ISO-8859-1? ()There might be several ways.)

Locales, timezones and time functions

  • What is the purpose of date_default_timezone_set()?
  • What are the types of locale settings that one must specify using a LC_* constant, when one is using the setlocale() function?
  • What is the ICU library and the Olsen database?

Strings

  • $foo= “My name is”; $bar = “Stan”;
    1. Write an expression using the above variables that evaluates to “My name is Stan” (including all spaces!)
    2. What is the value of $foo[4]?
    3. Write an expression using the the above two strings and string functions that evaluates to “Stan is my name”. Note that “my” is lowe case. You may not privide additional strings besides the two variables.
  • What pracice is encouraged in PHP 5.3+ to access individual characters in a string, brackets or braces?
  • What function will count the characters of a string?
  • What function will count the characters of a multi-byte encoded string in PHP 5 and lower?
  • What is heredoc and nowdoc?
  • How can you do a case insensitive comparison between two strings?
  • Write an expression that shows how to remove excess whitespace at the ends of a string.
  • What is a regular expression? Name a few regular expression related functions in PHP.
  • Describe a use case for the ctype family of functions.
  • $foo = array(“my”, “name”, “is”); $bar[] = “Stan”; All
    1. What will the ouput be from print_r($foo); print_r($bar);?
    2. Write a line of code that changes “Stan” to “Stanley”.
    3. Write an expression that evaluates to “My name is Stan”. If possible, avoid supplying an extra string for the space between “is” and “Stan” (Disregard the change you made to “Stan(-ley)” in the last question.)
    4. Write a line of code that sorts $foo starting with “is” and ending with “my”.
    5. Write code that iterates over $foo using both foreach, for and while () { list() = each(); ... next(); }. For each iteration output the key/value pair.
    6. $foo[] = $bar; print_r($foo); will output what? What kind of array is $foo now?

Array usage and array functions

  • What is an array in PHP? How do they compare to arrays in other languages?
  • What is an associative array?
  • Demonstrate at least 2 ways to create an array.
  • Demonstrate at least 2 ways to append a value to an array.
  • What are multi-dimensional arrays?
  • Why is $foo[bar] wrong? What error reporting level should you use to catch this?
  • How would you write a value from an array with string indexes in a string that has double quotes?
  • Array_walk takes an array-argument by reference, array_map by value. Write some code to demonstrate the difference.
  • How do you count the items in an array?
  • List some common sorting functions for arrays and describe what they do with one sentence for each.
  • Write a single line of code that swaps two variables using the list() language construct.
  • Write a few lines of code that will remove magic quotes from all superglobal arrays that might contain user submitted data.

Objects and classes

  • Identify 3 reasons you might decide to use Object Oriented Programming to develop a web applications rather than a procedural approach.
  • Explain the following terminology: Class, instance, property, method.
  • If you write (object) “foo”, what class will the resulting object be an instance of?
  • The teacher will provide code that defines a class for animals, a sub-class for birds and a sub-class for mammals (see resources).
    1. Why is it not possible to instantiate the class Animal?
    2. What properties in the classes illustrate encapsulation?
    3. The method tweet() in the class Bird is static. What does that mean? How should it be invoked?
    4. How would one access the constant HAS_WINGS from the Has_wings Interface?
    5. Write a suitable PHPDoc comment block for the class Animal and for its constructor method.
    6. An object of the class Bird can be said to be an instance of what? (List all 3 possibilities.)

    Write a continuous flow of code that does the following. Any questions about output shall be answered using comments in the code.

    1. Instantiate a variable called $gnu for a gnu Mammal, called “Richard Stallman”. What will this output?
    2. Instantiate a variable called $tux for a penguin Bird, that cannot fly and is called “Linus Torvalds”. What will this output?
    3. Instantiate a variable called $php for an elephant Mammal, called “Rasmus Leerdorf”. What will this output?
    4. Set the catch phrase for $tux to “My wife knows karate!”.
    5. Use the method sayCatchPhrase() to output $tux’s catch phrase.
    6. Make the elephant and the gnu friends of the penguin! What will this output?
    7. Write a line of code that outputs the elephant’s catch phrase. Start from $tux’s list of friends, not from $php, and use method chaining.
    8. What’s the output when the script stops executing?

Error handling and exceptions

  • What problems might occur on a production server if you have display_errors turned on?
  • What are parse errors, run time errors and logic errors?
  • There are constants that describe error levels in PHP. List at least 4 in increasing order of severity.

Server side architecture

  • Once you have located a class that will perform a desired task in your web application, how would you go about discovering how to use it? What information is essential to know before you can use it?
  • Describe a good architecture for PHP applications.
  • What is the include path?
  • What are relateive and absolute include paths?
  • In what way can one use mod rewrite to get good URL’s?
  • List and briefly explain at lest 3 aspects of good URL’s.

Handling posted data

  • How are the get and post methods different in the way they transmit information to/from the server? Provide examples when it is appropriate to use each.
  • What is magic quotes in PHP? Explain at least one argument against relying on magic quotes for security.
  • Why is the use of register globals a bad idea? Describe at least one way of mimicking the use of register globals that is equally bad.

Sending email

  • What is SMTP-injection?

Sessions and authentication

  • What is a session in PHP?
  • Why should one not use URL-rewriting to propagate session ID’s?
  • What PHP function should always be run when a user changes his or her authorization level?

Cookies

  • What is a cookie in HTTP?
  • If not manually specified, when does a cookie expire?
  • What is a server side only cookie? In what way are they more secure than regular cookies?
  • How might cookies be an infringement of personal integrity? What laws regulate the usage of cookies in your country?
  • List at least 3 ways how cookies can be used to improve the usability of a web site.
  • What is the difference between opening a file socket in text mode and binary mode?

File handling

  • In what way can functions like fopen() and file_get_contents() be security risks?
  • What special function should be used to move a file uploaded by the user?

Relational Database concepts and MySQL fundamentals

  • Explain the process of designing a database structure for a web application.
  • List at least 5 common DBMS’s and describe their main features and/or normal usage in a sentence or two for each.
  • What is the value NULL in database? What does it mean that a field is defined as NOT NULL?
  • List the datatypes that vis available in MySQL and briefly explain each one.
  • What is an index? How do they help selecting and sorting of data?
  • What is a primary key?
  • What is the purpose of auto incrementing fields?

SQL

  • What is SQL?
  • Explain the acronym CRUD and show relates to four SQL keywords.
  • Write a query to retrieve an entry with the id of 5 in a database table called articles.
  • Write a query that fetches the 5 newest entries from the table articles, sorted with the newest one first, assuming that there is a field called create_time that holds time and a field called create_date that holds the date an article was added.
  • Add a clause to the query above that uses the field author to
    • Write a query that retrieves data from two tables (instructor should provide table structures).
    • Write a query that alters the value of a field on a specific row (instructor should provide table structure).
    • Write a query that deletes a specific row (instructor should provide table structure).
    • Write a single query that creates two new rows in a table, where the primary key is auto incremented (instructor should provide table structure).

PDO

  • List the key steps required to grab content from a database and display it on a page.
  • In what version of PHP was PDO introduced? List at least 5 DBMS’s that are supported by PDO.
  • What kind of data access abstraction will PDO provide? What database abstraction will it not provide?
  • What are the benefits of prepared statements?

The mysql and mysqli functions

  • What capabilities are not provided by the mysql functions, but by mysqli and PDO?
  • What function shall be used to escape all user submitted data for safe usage in an SQL query, using the mysql fiunctions?
  • In 2-4 sentences each, describe the following: PEAR, PECL and SPL.

SPL, PEAR and Frameworks

  • List some common PHP applications or CMS’s built with PHP.
  • What is a framework? Why or when would you use one?
  • List some major websites that allow for users to have PHP-modules to extend its functionality.

Web Services, API’s, RSS, JSON and Ajax

  • Draw a diagram/flow chart that explains the difference between Ajax and normal page reloads, from a client/server interaction perspective.
  • In what character encoding is XHR-submitted data (regardless of the web page’s encoding)?
  • What is a web service? (Briefly describe the concept.)
  • What is JSON? (Briefly describe the concept.)
  • What is RSS? (Briefly describe the concept.)
  • List a few web sites that offer a public API.

Shared hosting

  • A web hosting company seems to offer a valuable shared hosting plan. However, they are not very specific about the technical details. Write an email of inquiry addressed to their technical marketing staff asking everything you, as a potential customer would need to know, besides amount of data storage and the price.