In a new post to his site Stoimen Popov makes the recommendation to not call the destructor explicitly in your code and provides some alternatives.
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++” says the documentation for destructors. […] Well, as you can not call the constructor explicitly […] so we should not call the destructor explicitly. The problem is that I’ve seen this many times, but it’s a pity that this won’t destroy the object and it is still a valid PHP code.
He talks about
__destruct and it’s role in PHP’s set of "magic methods" and what they exist to do. He then gets into a few examples of what code could look like that uses a destructor and the difference between normal handling calling the destructor explicitly. The main differences is that calling it explicitly does not destroy the object, it’s basically like calling any other method. He does include an interesting method for destroying the object – setting it to null – and notes that the destructor fires then too. He also points out a few interesting things about cloning objects and how object references work when setting nulls as in the previous example.
On the SitePoint PHP blog there’s a new tutorial posted showing you how to use the Halite package to encrypt the contents of emails. The Halite library sits on top of the libsodium functionality to provide tested, hardened cryptographic results.
Cryptography is a complex matter. In fact, there is one golden rule: „Don’t implement cryptography yourself.“ The reason for this is that so many things can go wrong while implementing it, the slightest error can generate a vulnerability and if you look away, your precious data can be read by someone else.
[…] Some libraries out there implement cryptography primitives and operations, and leave a lot of decisions to the developer. […] Nevertheless, there is one library that stands out from the rest for its simplicity and takes a lot of responsibility from the developer on the best practices, in addition to using the libsodium library. In this article we are going to explore Halite.
The tutorial then starts of helping you get the libsodium package installed on your system (assuming it’s unix-based). They then start on the sample application – a basic "email" client able to send/receive messages between users. They set up RESTful endpoints to get the messages, use the Doctrine ORM for a database interface and show the use of the Halite
Crypto class to encrypt/decrypt the message contents.
Matt Stauffer has a new post to his site where he’s put together an in-depth look at Laravel Echo, a feature included in newer versions of the framework that makes it easy to integrate websockets into your Laravel-based application.
A few weeks ago, Taylor Otwell introduced another branded product within the Laravel line: Laravel Echo. So far, the only coverage it’s gotten has been his Laracasts video intro, but I recently wrote it up for my book and wanted to share that with you. What follows is an excerpt from Laravel: Up and Running, heavily modified to make sense in a blog format.
The TutsPlus.com site has posted the next part of their series showing the use of the PHP CodeSniffer tool with WordPress. In the first part of the series they introduced "code smells" and build on that in part two with the installation and use of PHP CodeSniffer to detect these smells.
In the first article of this series, we defined code smells and looked at a few examples of what they are and how we may refactor them so the quality of the code is improved.
[…] Ultimately, we’re working towards implementing WordPress-specific code sniffing rules, but before we do that it’s important to familiarize yourself with PHP CodeSniffer. In this article, we’re going to take a look at what PHP CodeSniffer is, how to install it, how to run it against an example script, and how to refactor said script. Then we’ll look at how we’re going to move forward into WordPress-specific code.
The tutorial then shows you how to get the tool installed using Composer, not the PEAR method. They help you install Composer then create the simple project with a
composer.json configuration file defining the dependency. They provide a sample bit of code to run the analysis against and an example of the output showing violations of the coding standard.
Jordi Boggiano has posted some updated statistics around the use of the Packagist site around PHP version requirements and the relation of package downloads to PHP versions.
Last year I posted stats about PHP versions, and the year before as well, both time in November. However this year I can’t wait for November as I am curious to explore the PHP7 uptake!
A quick note on methodology, because all these stats are imperfect as they just sample some subset of the PHP user base. I look in the packagist.org logs of the last 28 days for Composer installs done by someone. Composer sends the PHP version it is running with in its User-Agent header, so I can use that to see which PHP versions people are using Composer with.
He compares the previous statistics against the ones gathered back in November 2015, both in numbers and graphs. He shows the stats for the PHP versions being used and for the PHP versions that are required. It’s interesting to see that there’s been a good uptick in supported versions including PHP 7.0+.
On the SitePoint PHP blog there’s a new tutorial posted from Bruno Skvorc showing you how to use Nitpick CI to "nitpick" over coding standards and rules in your PHP code.
There are many ways to make sure your code respects a given code standard – we’ve covered several before. But enforcing a standard team-wide and making sure everyone knows about mistakes before they’re applied to the project isn’t something that’s very easy to do. Travis and Jenkins can both be configured to do these checks, but aren’t as easygoing about it as the solution we’re about to look at: Nitpick CI.
He starts by getting a sample project bootstrapped and pushes it up to GitHub so the Nitpick service can access it. He then switches over to the Nitpick side and shows the setup of an account and a new project pointing to the newly created repo. He then includes the process and results of two kinds of pushes: non-code (README update) and both a valid/invalid code update. He shows examples of the comments the Nitpick service makes directly on the code and a patch to fix the issues.