0
0
PHPprogramming~20 mins

Why modern PHP matters - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modern PHP Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of typed properties in PHP 7.4+
What is the output of this PHP code using typed properties introduced in PHP 7.4?
PHP
<?php
class User {
    public int $id;
    public string $name;

    public function __construct(int $id, string $name) {
        $this->id = $id;
        $this->name = $name;
    }
}
$user = new User(1, "Alice");
echo $user->id . ' - ' . $user->name;
A1 - Alice
BError: Typed property must be initialized
C1-Alice
D1, Alice
Attempts:
2 left
💡 Hint
Typed properties require initialization before use.
🧠 Conceptual
intermediate
1:30remaining
Why use PHP 8's union types?
Which of the following best explains the benefit of union types introduced in PHP 8?
AThey allow a variable to accept multiple specified types, improving code clarity and error checking.
BThey automatically convert all types to strings for easier output.
CThey remove the need for any type declarations in functions.
DThey force all variables to be of a single type only.
Attempts:
2 left
💡 Hint
Think about how specifying multiple types helps programmers.
🔧 Debug
advanced
2:00remaining
Identify the error with nullsafe operator
What error does this PHP 8 code produce?
PHP
<?php
class Profile {
    public ?string $email = null;
}
$user = null;
echo $user?->profile?->email;
ANotice: Undefined variable 'user'
BFatal error: Trying to get property of non-object
CParse error: syntax error near '?->'
DNo output, prints nothing
Attempts:
2 left
💡 Hint
The nullsafe operator returns null if the variable is null.
📝 Syntax
advanced
2:00remaining
Correct syntax for match expression
Which option shows the correct syntax for PHP 8's match expression?
PHP
switch ($status) {
    case 1:
        $result = 'One';
        break;
    case 2:
        $result = 'Two';
        break;
    default:
        $result = 'Other';
}
A
$result = match($status) {
    1 =&gt; 'One';
    2 =&gt; 'Two';
    default =&gt; 'Other';
};
B
$result = match($status) {
    1: 'One',
    2: 'Two',
    default: 'Other'
};
C
$result = match($status) {
    1 =&gt; 'One',
    2 =&gt; 'Two',
    default =&gt; 'Other',
};
D
$result = match $status {
    1 =&gt; 'One',
    2 =&gt; 'Two',
    default =&gt; 'Other'
};
Attempts:
2 left
💡 Hint
Look for the arrow syntax and commas between cases.
🚀 Application
expert
2:30remaining
How does PHP 8's JIT improve performance?
Which statement best describes how PHP 8's Just-In-Time (JIT) compiler improves PHP performance?
AJIT caches PHP source files to reduce disk reads.
BJIT compiles PHP code into machine code at runtime, speeding up CPU-intensive tasks.
CJIT converts PHP code into JavaScript for faster browser execution.
DJIT removes all type checks to make code run faster.
Attempts:
2 left
💡 Hint
Think about how turning code into machine instructions helps speed.