Skip to content

Commit 69b3cbb

Browse files
committed
Problem file
1 parent decd9cc commit 69b3cbb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
You have been given a piece of code (look for `throw-an-expression.php` in your working directory) which is checking the requested URL and throwing an exception when a secret area of the website is accessed.
2+
3+
If the request is allowed the `Welcome!` is printed out.
4+
5+
Traditionally, pre PHP 8, an exception throw has been a statement. There are certain places where statements can be used, and only expressions can. For example in ternaries and short closures, only expressions can be used.
6+
7+
PHP 8 has changed that, throw statements are now expressions.
8+
9+
----------------------------------------------------------------------
10+
Your task is to convert the `if` statement to one line of code, using the ternary operator.
11+
12+
### The advantages of throwing being an exception
13+
14+
* It is possible to throw an exception in a short closure
15+
* It is possible to throw an exception in a ternary or coalesce operation
16+
17+
----------------------------------------------------------------------
18+
## HINTS
19+
20+
Documentation on throwing exception can be found by pointing your browser here:
21+
[https://www.php.net/manual/en/language.exceptions.php]()
22+

0 commit comments

Comments
 (0)