You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the `capital` property is null, the variable `$capitalPopulation` will also be null. Previously, without the null safe operator, this would be achieved like so:
13
+
If the `$capital` property is null, the variable `$capitalPopulation` will also be null. Previously, without the null safe operator, this would be achieved like so:
14
14
15
15
```php
16
16
$capitalPopulation = null;
@@ -44,25 +44,24 @@ Export the `$user` data to a CSV with the following columns:
* The columns should read exactly as above, any mistake will trigger a failure
49
-
* There should be one row for the column headers and one for the data
50
-
* Any properties which are null on the user should be printed as empty fields in the CSV
51
-
* The file should be named `users.csv` and exist next to your submission file (eg in the same directory)
47
+
* The CSV should be comma delimited.
48
+
* The columns should read exactly as above, any mistake will trigger a failure.
49
+
* There should be one row for the column headers and one for the data.
50
+
* Any properties which are null on the user should be printed as empty fields in the CSV.
51
+
* The file should be named `users.csv` and exist next to your submission file (eg in the same directory).
52
52
53
53
And finally, the most important part, all properties which may be `NULL` should be accessed using the null safe operator!
54
54
55
55
### Advantages of the null safe operator
56
56
57
-
* Much less code for simple operations where null is a valid value
57
+
* Much less code for simple operations where null is a valid value.
58
58
* If the operator is part of a chain anything to the right of the null will not be executed, the statements will be short-circuited.
59
-
* Can be used on methods where null coalescing cannot `$user->getCreatedAt()->format() ?? null` where `getCreatedAt()` could return null or a `\DateTime` instance
59
+
* Can be used on methods where null coalescing cannot `$user->getCreatedAt()->format() ?? null` where `getCreatedAt()` could return null or a `\DateTime` instance.
Remember your program will be passed no arguments. There will be a `User` object populated for you under the variable `$user`.
65
-
It is available at the beginning of your script.
64
+
Remember your program will be passed no arguments. There will be a `User` object populated for you under the variable `$user`. It is available at the beginning of your script.
66
65
67
66
Documentation on the Null Safe Operator can be found by pointing your browser here:
0 commit comments