Skip to content

Commit b1dc1ad

Browse files
committed
Initial problem
1 parent 67919c0 commit b1dc1ad

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
For a long time in PHP the types have been independent & solitary, it's now time for the uprising, and the uniting of types.
2+
3+
Create a program which adds up and prints the result of all the arguments passed to the program (not including the program name).
4+
5+
In the process you should create a function named `adder` which accepts these numbers as a variadic parameter.
6+
7+
The type of the parameter should be a union of all the types of numbers we might pass to your program.
8+
9+
We will pass to your program any number of random numbers which could be integers, floats or strings. Your `adder` function
10+
should only accept these types.
11+
12+
You should output the sum of the numbers followed by a new line.
13+
14+
How you print and add the numbers is up to you.
15+
16+
### The advantages of match
17+
18+
* Match uses strict equality, unlike switch which uses weak comparison and can lead to subtle bugs.
19+
* Each match arm does not fall through without a break statement, unlike switch.
20+
* Match expressions must be exhaustive, if there is no default arm specified, and no arm matches the given value, an `UnhandledMatchError` is thrown
21+
* Match is an expression and thus returns a value, reducing unnecessary variables and reducing the risk of accessing undefined variables.
22+
23+
24+
----------------------------------------------------------------------
25+
## HINTS
26+
27+
Remember the first argument will be the programs file path and not an argument passed to the program.
28+
29+
The function must be called `adder`.
30+
31+
It is up to you to pass the numbers to your function.
32+
33+
Documentation on the union types can be found by pointing your browser here:
34+
[https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.union]()
35+
36+
----------------------------------------------------------------------
37+
## EXTRA
38+
39+
You should access `$argv` directly to fetch the numbers (we have casted the arguments from strings to their respective types)
40+
41+
Think about the return type of your `adder` function - you could declare it as a float.

0 commit comments

Comments
 (0)