readyforhires

Beginner PHP test (Beginner)

25 questions · 30 minutes · Free

Syntax, arrays, functions and forms.

Take the Beginner PHP test

What it covers

Interview format

Earn a certificate

The Beginner PHP test is one of the 6 tests of the WordPress Developer learning path. Pass it and the other 5 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.

Sample learning path certificate for WordPress Developer, made out to “Your name” and marked SAMPLE
Pass with 70% or more to earn a verifiable certificate. This is a sample: yours carries your name, the date you earned it and its own verify code.

Sample questions

5 sample questions from the Beginner PHP test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.

  1. In a PHP application, a user may choose to leave a form field blank. How would you assign a value to the variable $userInput to indicate that no data was provided by the user?

    1. The variable $userInput is assigned an empty string, indicating no data was provided by the user.
    2. The variable $userInput is assigned a boolean false, indicating no data was provided by the user.
    3. The variable $userInput is assigned a default value of 0, indicating no data was provided by the user.
    4. The variable $userInput is assigned a null value, indicating no data was provided by the user.

    Answer: D. The variable $userInput is assigned a null value, indicating no data was provided by the user.

    When a variable is assigned a null value, it indicates that no value has been provided or that the variable is intentionally empty. This is commonly used in scenarios where user input may be optional, and the absence of input needs to be explicitly recognized in the application logic.

  2. Where is a cookie stored?

    1. It is stored in the browser but only for the duration of the page session.
    2. It is stored in the browser and sent with each request.
    3. It is stored in the server's memory and is not accessible to the client.
    4. It is stored on the server and accessed via a session ID.

    Answer: B. It is stored in the browser and sent with each request.

    Cookies are stored in the browser and sent with each request. They are not stored on the server, unlike sessions, which store data on the server and only keep a session ID in the browser.

  3. You are working on a PHP web application that requires storing user login information across multiple pages. After the user logs in, you store their username in a session variable. How should you retrieve this session variable on a subsequent page?

    1. Use the $_COOKIE superglobal to access the variable.
    2. Use the $GLOBALS superglobal to access the variable.
    3. Use the $_SESSION superglobal to access the variable.
    4. Use the $_GET superglobal to access the variable.

    Answer: C. Use the $_SESSION superglobal to access the variable.

    In PHP, session data is stored in the $_SESSION superglobal array. To retrieve session data, you must access it through this array. Other options are incorrect because they either reference incorrect superglobals or describe unrelated processes.

  4. Which of the following is the best practice for data sanitization when handling user input in a PHP application that interacts with a database?

    1. Use prepared statements with parameterized queries.
    2. Sanitize input using regular expressions only.
    3. Directly insert user input into the SQL query string.
    4. Store user input in a separate log file without database interaction.

    Answer: A. Use prepared statements with parameterized queries.

    Prepared statements with parameterized queries are the most effective way to sanitize data and prevent SQL injection attacks. Other options either do not fully sanitize data or are not secure practices for handling user input in a database context.

  5. Which function should be used to check if a specific key exists in an array, even if the value associated with that key is `null`?

    1. isset
    2. in_array
    3. array_key_exists
    4. empty

    Answer: C. array_key_exists

    The `array_key_exists` function checks if a specific key exists in an array, regardless of the value associated with that key. In contrast, `isset` returns false if the key exists but the value is `null`. Therefore, `array_key_exists` is the correct choice when checking for the presence of a key in an array, even if the value is `null`.

Frequently asked questions

How many questions are in the Beginner PHP test?
25 questions (15 multiple choice, 8 multi-answer, 2 predict-the-output), with 30 minutes to answer them.
What does the Beginner PHP test cover?
Variables and types, Arrays, Functions, Forms and superglobals, Sessions and cookies.
Is the Beginner PHP test free?
Yes. It is free to take with a readyforhires account.
What level is the Beginner PHP test?
Beginner, in Backend.

More Backend tests

Roles that test these skills

Companies that test these skills

All practice tests · All Backend tests

Last updated