close

April 2024 only! Join our Discord free of charge.

Slick­Stack
Lightning-fast WordPress on Nginx

PHP Strict Types

PHP gets enough flack for being insecure and untamed. Moving toward stronger security and stricter coding is one of the benefits of PHP 7+

The short answer is you should pretty much always use strict_types whenever possible, these days. However, if you’re upgrading old code, you of course need to be sure that everything works correctly after adding strict_types, because the PHP engine will interpret it more strictly.

It is also worth nothing that current implementation is not very aggressive, so you can still include PHP files (etc) in other files, and it will not necessarily break them if their code does not follow same type suit.

And yes, you have to declare it at the top of every single script 🙂

Ref: https://stackoverflow.com/questions/48723637/what-does-strict-types-do-in-php
Ref: https://stackoverflow.com/questions/37111470/enabling-strict-types-globally-in-php-7
Ref: https://github.com/Automattic/phpcs-neutron-standard/issues/20
Ref: https://www.quora.com/Are-strict_types-in-PHP-7-not-a-bad-idea

About the Author

Jesse Nickles

Jesse is the lead developer for the SlickStack project and also for HoverCraft, the accompanying free WordPress theme. He has been customizing WordPress for both personal websites and SEO clients for over 15+ years, with a focus on simplicity and longevity.

Tags:

Thanks to our generous sponsors for their support!