There are some very helpful ways to organize classes and objects in PHP. Interfaces, Traits, and Abstract Classes can work together to make code that follows the rules of abstraction. Using these OOP features in PHP allows us to create code that is easy to extend and maintain, saving time and money down the road. Let’s look at what these structures are as well as how and when abstract classes, traits, and interfaces can be useful in Object Oriented PHP.
How should passwords be stored? The short answer is: DON’T! I see countless posts on reddit and around the web from people who are trying to figure out how to use PHP’s “new” password functions. These new functions are awesome in that they have finally made it so that those who are not security specialists can start managing passwords the right way. PHP’s password functions do things the right way and give us a means by which to ensure our sites can continue to stay secure.
Generators are one of the coolest things in modern PHP! They were introduced in PHP v5.5 and expanded even more in PHP 7. I’ve read a lot about concurrency and how many event loops utilize these generators to interrupt code to do a little bit of everything at (seemingly) the same time. However, this is not the most useful point of generators in typical PHP applications. Let’s take a look at a couple ways that Generators can make life easier in typical, synchronous, PHP applications.
I recently decided to create a library that could handle asynchronous SQL queries and realized in the process that, while I am very comfortable using composer to install other people’s libraries I actually had no clue how to make and publish my own library! I’m by far no expert on this, but let’s take a look at how I went about getting it set up and testing things.
Asynchronous SQL can seem like a daunting task if you are not using an asynchronous library. These libraries often add a lot of overhead to an existing application and force you to do things their way. So let’s look at how to implement asynchronous SQL queries in your existing code from scratch.
Recursive code can be very confusing and frustrating at first, but is a necessity if you are trying to accomplish certain tasks in an expandable, decoupled way. I recently needed to make a function that could build a multi-dimensional array from a form. The problem is that the depth of the array is completely fluid as the form is made by nested “rules” which play off each other, allowing the user to build a very complex rule set. Without going into the details of of the proprietary code for my company, let’s take a look at the technique I chose and …
Variables are pretty straightforward in PHP. Anything that starts with a $ is a variable. However, there are some things about them that can be somewhat confusing. Let’s do an overview of Variables in PHP. Type Juggling In PHP, variables will automatically convert to whatever type is needed. Most of these transformations are very natural and it allows programmers to spend the majority of time working on the application logic. However, every now and then some of the automatic conversions can get you in trouble if you’re not prepared. For example, if you try to multiply an integer and a …
WebSockets have been around for quite some time, but are recently gaining a lot of popularity due to their ability to initiate messages from the server to the user, allowing the website to update on the fly! In this article I’ll be taking a look at what WebSockets are and how you can implement them using asynchronous PHP and Ratchet.