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
Copy file name to clipboardExpand all lines: README.md
+17-3Lines changed: 17 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,26 +171,40 @@ function paintCar(&$car) {
171
171
172
172
###Use default arguments instead of short circuiting or conditionals
173
173
174
+
**Not good:**
175
+
176
+
This is not good because`$breweryName` can be`NULL`.
177
+
178
+
```php
179
+
function createMicrobrewery($breweryName = 'Hipster Brew Co.')
180
+
{
181
+
// ...
182
+
}
183
+
```
184
+
174
185
**Not bad:**
175
186
187
+
This opinion is understandable than the previous version, but it better controls the value of the variable.
188
+
176
189
```php
177
190
function createMicrobrewery($name = null)
178
191
{
179
192
$breweryName = $name ?: 'Hipster Brew Co.';
180
193
// ...
181
194
}
182
-
183
195
```
184
196
185
-
**Good for PHP 7+**:
197
+
**Good**:
198
+
199
+
If you support only PHP 7+, then you can use[type hinting](http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration) and be sure that the`$breweryName` will not be`NULL`.
186
200
187
201
```php
188
202
function createMicrobrewery(string $breweryName = 'Hipster Brew Co.')