@@ -71,7 +71,7 @@ addExpireAt(86400);
7171``` php
7272// Declare them as capitalized `const` globals.
7373interface DateGlobal {
74- const SECONDS_IN_A_DAY = 86400;
74+ const SECONDS_IN_A_DAY = 86400;
7575}
7676
7777addExpireAt(DateGlobal::SECONDS_IN_A_DAY);
@@ -85,6 +85,7 @@ addExpireAt(DateGlobal::SECONDS_IN_A_DAY);
8585$address = 'One Infinite Loop, Cupertino 95014';
8686$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/';
8787preg_match($cityZipCodeRegex, $address, $matches);
88+
8889saveCityZipCode($matches[1], $matches[2]);
8990```
9091
@@ -93,26 +94,29 @@ saveCityZipCode($matches[1], $matches[2]);
9394$address = 'One Infinite Loop, Cupertino 95014';
9495$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/';
9596preg_match($cityZipCodeRegex, $address, $matches);
97+
9698list(, $city, $zipCode) = $matchers;
9799saveCityZipCode(city, zipCode);
98100```
99101** [ ⬆ back to top] ( #table-of-contents ) **
100102
101103###Avoid Mental Mapping
104+ Don’t force the reader of your code to translate what the variable means.
102105Explicit is better than implicit.
103106
104107** Bad:**
105108``` php
106109$l = ['Austin', 'New York', 'San Francisco'];
107110
108111foreach($i=0; $i<count ($l); $i++) {
112+ $li =$l[$i];
109113oStuff();
110114doSomeOtherStuff();
111115 //...
112116 //...
113117 //...
114- //Wait, what is `l ` for again?
115- dispatch(l );
118+ //Wait, what is `$li ` for again?
119+ dispatch($li );
116120}
117121```
118122
@@ -179,7 +183,7 @@ function createMicrobrewery($name = null) {
179183** Good** :
180184``` php
181185function createMicrobrewery($breweryName = 'Hipster Brew Co.') {
182- // ...
186+ // ...
183187}
184188
185189```
@@ -198,7 +202,7 @@ of the time a higher-level object will suffice as an argument.
198202** Bad:**
199203``` php
200204function createMenu($title, $body, $buttonText, $cancellable) {
201- // ...
205+ // ...
202206}
203207```
204208