1. iteratable psuedo type
This is a new type that can be used to more generically indicate that what is being passed can be iterated over using something like foreach. Prior to this, you could not type hint an iterable custom object.
2. Closure from callable
Allows you to create a closure from any callable function. This new technique will help catch typos up front, and improves performance.
3 and 4. Square bracket syntax for list.
This one is a shorthand for list($a, $b, $c) = [‘a’,’b’,’c’]; We can now write [$a, $b, $c] = [‘a’, ‘b’, ‘c’]; It also now allows you to specify the keys, and supports multi-dimensional arrays.
5. Class constant visibility
Class constants can now explicitly be set to protected, private, or public to aid in information hiding.
6. Nullable types
Now you can type hint, and allow optional null. Just put a ? in front of the type hint. Applies to function params and return types.
7. Void functions
You can now specify that a function may only return void. function foo() : void
8. Catching multiple exception types
Catch can now have more than one exception type. Just separate them with a | like catch(FooException | BarException)
9. Too few arguments exception
This one just means that in PHP 7.1, calling a function without required parameters will trigger an Error exception. It was a warning previously, but now you have to deal with it. This is a potentially breaking change when upgrading.
Recently, after setting up another virtual host on my Linux server, for a WordPress site, permalinks were not working. Any page other than home was getting a 404 error. I searched Google for help, but kept finding the same advise, which was basically to make sure that the .htaccess file was writable and had the correct permissions.
Sadly, it took me 2 days to solve this puzzle. (About 3-4 hours total.)
This was the second time I was doing this, so I knew I had figured it out once before, and done all the work to learn how it is done, but for some reason the dots just weren’t connecting for me. It was very frustrating!
So now I am documenting it so that if I ever add another site, I’ll have a guide to remind me of exactly what is required to get it done in minutes, rather than hours.
It was at this point that I realized that the permalinks were not working.
I began confirming that the .htaccess was correct. Then I remembered that I had done something to avoid .htaccess last time because I had read at least one page showing how it negatively affects site performance.
I started poking around the .conf file, adding in the Directory block, and making sure it contained the code that the .htaccess file had.
But the changes were not having any effect. I was a bit baffled as to why.
Finally, I realized that I was not in the right file! Let’s Encrypt creates a second .conf file, and that is where the code needs to be!
The first .conf file has :80 in it, and handles HTTP traffic, and it redirects to HTTPS, so then the .conf from Let’s Encrypt is active. It has :443 in it, and that is where the code needs to be.
I opened up the :443 .conf file from the first site and immediately saw the code I was looking for. A few copy/paste’s later and the new site was working properly, and the mystery was solved.
The :443 .conf file has a Directory block in it, which tells the web server not to look for .htaccess files. This improves performance. All that was required was to copy the .htaccess file content into that section.
Are you also a PHP programmer? I’ve got other blog entries that you might be interested in!
I have been programming for almost 20 years. It all started with Basic and RPG III way back in high school, and have played around with many languages. PHP is my main language today.
Some sites I have built:
For fans of BMX legend Scotty Cranmer: https://ScottyFan.com
Meet my Basenji’s Graham and Ginger: https://BarooBoos.com
Meet my newest Basenji, Zulu: https://ZuluJoy.com