Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Learn to use Model Factories in Laravel 5.1
Oct 08, 2015 @ 10:46:21

On the Laravel News site there's a tutorial helping you learn to use Model factories in your Laravel 5.1+ application. These factories make it easy to create instances of "fake" models that can be interacted with as if they were the real thing.

These have several use cases with the two biggest being–testing and database seeding. Let’s take a deeper look at this feature by building out the beginning of a little fictional app.

They provide a situation where these factories can solve a potential problem: making an application easier to test because of the (potentially) high volume of customers. He walks you through the creation of a new application and building out the models and matching migrations. Next up is the generation of the database seed values and, finally, the creation of the fake models and the code needed to connect it all together. The post ends with a look at using these factories to generate models in tests, creating them with simple data and some of the other features they offer.

tagged: model factory laravel fake tutorial testing introduction

Link: https://laravel-news.com/2015/10/learn-to-use-model-factories-in-laravel-5-1/

Paragon Initiative:
How to Safely Implement Cryptography Features in Any Application
Oct 07, 2015 @ 11:51:41

The Paragon Initiative blog has posted a new article showing you how to safely implement cryptography in any PHP-based application (or really just about any application) with the help of libsodium.

Why not {Mcrypt, OpenSSL, Bouncy Castle, KeyCzar, etc.}? These cryptography libraries are really building blocks that by and large must be used, with expert care, to build the interfaces you want developers to use. In most cases, libsodium is the interface you want developers to use. [...] By default, these libraries don't provide [authenticated encryption](https://tonyarcieri.com/all-the-crypto-code-youve-ever-written-is-probably-broken). Most of them force developers to use RSA (or ECDSA but certainly not EdDSA), which is [hard to get right](http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html) and for which [index calculus attacks are improving each year](https://events.ccc.de/congress/2014/Fahrplan/system/attachments/2501/original/20141227.pdf).

He goes on to talk about NaCI as a possible option (libsodium is from a fork of it) but points out that NaCI isn't as easily available as libsodium to non-C/Python developers. He shares a few reasons why he thinks "libsodium is so great" and a few reasons not to use it (mostly dealing with outside limitations, not technical ones). Finally he points you in the right direction to help you get started using libsodium for PHP as a PECL extension.

tagged: cryptography feature safe guide tutorial introduction pecl extension

Link: https://paragonie.com/blog/2015/09/how-to-safely-implement-cryptography-in-any-application

Woody Gilk:
Immutable Data Structures in PHP
Sep 23, 2015 @ 11:48:34

Woody Gilk has posted an article to his site looking at immutable data structures in PHP and a library that's come from the research and work he did to implement them in PHP.

As someone who most often works with PHP I often find myself envious of the more advanced data structures that are present in a language like Python. As an experiment, I decided to see if it would be possible to bring some of those basic structures to PHP while also preserving immutability. The result of this experiment is Destrukt.

He starts off talking about immutable data structures and introducing some of the basic concepts and usage around them. He notes that they "cannot be modified by accident" and how, if they do need to be changed, they'd actually be reassigned not updated. He then talks about PHP arrays, how they're normally used in PHP and how their flexibility can lead to potential issues in the code. His library implements more strict versions of the same functionality in the form of dictionaries, orderedlists, unorderedlists and sets. He includes examples of using the library to create these objects and how to get the data back out of them for evaluation.

tagged: immutable data structure introduction destrukt dictionary orderedlist unorderedlist set

Link: http://shadowhand.me/immutable-data-structures-in-php/

SitePoint PHP Blog:
Conquering Instagram with PHP and the Instagram API
Sep 22, 2015 @ 12:57:21

The SitePoint PHP blog has a tutorial posted that shows you how to "conquer" the Instagram API in your PHP application and integrate it into your application with the help of the Guzzle HTTP client.

Instagram’s API allows us to interact with data such as user info, media (photos and videos), likes, comments, and tags. For example, you can search for media around a specific location and filter the results by time. The API also allows us to post comments or like specific media. For now, only uploading media isn’t supported. You can always look at the API endpoints documentation if you want to know about the full functionality.

They start by talking about the two types of API calls (authenticated/unautheticated) and the limits that are included with each. From there the tutorial shows you how to register a new application, get a new client ID and how to use the API console to test out requests. Next they help you get the [Guzzle]((http://guzzle.readthedocs.org/en/latest/) library installed and connect it to the Instagram API with your client credentials. They integrate this into a simple Slim application using Twig as a templating layer to allow for the OAuth approval process, fetching an access token for the later requests.

With the connection made, they show you how to make requests to do thing like make tag searches, get user feed information (and searches), geographic searches and handling pagination. They also include a link to a PHP Instagram library that can help simplify the process, complete with code examples.

tagged: tutorial instagram api introduction library oauth slim twig

Link: http://www.sitepoint.com/conquering-instagram-with-php-and-the-instagram-api/

Zend Developer Zone:
PHP 7 Quick Overview
Sep 21, 2015 @ 13:51:26

On the Zend Developer Zone they've posted an article talking about the upcoming major version of PHP, PHP 7, and what you can expect from it. It's a brief overview of the new features and functionality included in this big update.

PHP7 is around the corner. According to the wiki time table if everything goes well, it is expected to be released in November 2015. Many of us are excited to learn the language level features and it’s performance.

The article touches on the highlights of:

  • Performance boosts
  • Null Coalesce Operator
  • Scalar Type Hints
  • Weak type mode
  • Strict mode
  • Handling Exceptions
  • Return Type Declaration
  • Reserve More Types in PHP 7
  • Timezone warning

There's a lot of new things coming, so check out this guide for a quick overview and to get up to speed before it's here.

tagged: php7 overview introduction list feature improvement

Link: http://devzone.zend.com/6656/php-7-quick-overview/

Zend Developer Zone:
A new type of PHP, part 2: Scalar types
Sep 16, 2015 @ 09:09:26

The Zend Developer Zone has posted the second part of their series (from community member Larry Garfield) about scalar types in PHP 7, one of many features in this "coming soon" release. You can find part one of the series here.

In our last installment, we talked about the benefits of more robust variable typing in PHP 7, and specifically the new support for typed return values. That is already a big boon to the maintainability of our code, but PHP 7 goes a step further. So far, we’ve only talked about typing against classes and interfaces. We’ve been able to type against those (and arrays) for years. PHP 7, however, adds the ability to type against scalar values too, such as int, string, and float.

But wait. In PHP, most primitives are interchangeable. [...] Much the same as return types, scalar types offer greater clarity within the language as well as the ability to catch more bugs earlier. That, in turn, can help encourage more robust code in the first place, which benefits everybody.

He starts by looking at the four new types that have been added in PHP 7: int, float, string, and bool. He includes a code example showing each of them in use on class interfaces and functions. He steps through the code example, explaining how the return type checking is handled for each instance. He also talks about how return type hinting can also benefit static analysis tools, allowing them to potentially find bugs in return values easier than before. Finally he covers strict mode, the method for enforcing types in your code and preventing PHP from doing any "magic" type switching for you. He also includes a code example of this functionality and how, with it enabled, it would have caught an error in his example on a integer vs string input.

tagged: scalar type hints introduction php7 strict example

Link: http://devzone.zend.com/6622/a-new-type-of-php-part-2-scalar-types/

Alejandro Celaya:
My first approach to Zend Expressive
Sep 14, 2015 @ 10:50:40

The team behind the Zend Framework recently released a microframework of sorts that makes use of middleware as its primary location for processing: Zend Expressive. In this post to his site Alejandro Celaya takes a "first approach" to this new framework and shares some of what he's discovered.

One of the trending topics in the PHP world nowadays is the one about microframeworks. It started some years ago with Slim and Silex, but recently it has been an explossion of new microframeworks. First, Slim's team announced the third version of its own framework, which implemented the psr-7 HTTP standard by taking advantage of the middleware concept. [...] Then, Laravel launched the Lumen project, which is another microframework based on Laravel components [and] Zend framework's team launched Zend Expressive, which is similar to Slim 3 in the fact that it works with middleware and psr-7, built on top of zend-stratigility and zend-diactoros.

He starts the post off answering two "why" questions: "why microframeworks" and "why Zend Expressive". He then gets into the technical details, comparing some of the basic route handling across the different microframework projects (with code examples). He shows how Expression allows the use of a service container as the main object instead of just defining routes (and what routers that's compatible with). He briefly covers some of the other piece of the Expression puzzle: template library support, the service container, error management and some other considerations to think about with evaluating the tool.

tagged: zendexpressive expressive microframework introduction overview comparison

Link: http://blog.alejandrocelaya.com/2015/09/12/my-first-approach-to-zend-expressive/

Paragon Initiative:
Using Libsodium in PHP Projects
Sep 02, 2015 @ 13:25:18

The Paragon Initiative site has posted a new guide to helping you integrate libsodium into your application to provide additional cryptographic functionality in addition to things like mcrypt and crypt

You shouldn't need a Ph.D in Applied Cryptography to build a secure web application. Enter libsodium, which allows developers to develop fast, secure, and reliable applications without needing to know what a stream cipher even is.

After reading this brief electronic manual, you should know what libsodium is, what features it has, and how to install it (both the library and the PHP extension from PECL). [You should also] generally understand which cryptography tool to use for a specific scenario [and] be capable of writing production-quality code that uses libsodium.

The guide (still a work in progress) starts by explaining what libsodium is and what it has to offer over other encryption methods. It talks about the role of random data in encryption, a few basic crypto concepts (like key-based encryption and hashing) and finally gets into some of the more advanced features of the libsodium extension.

Additionally, the guide is also open source so if you'd like to contribute, just submit a pull request for consideration.

tagged: paragoninitiative libsodium guide introduction advanced encryption

Link: https://paragonie.com/book/pecl-libsodium

SitePoint PHP Blog:
Logging with Monolog: From Devtools to Slack
Sep 02, 2015 @ 11:48:15

The SitePoint PHP blog has posted a tutorial showing you how to connect Monolog with Slack, a popular logging tool for PHP and a well-used communication (chat) service for development groups and projects. The basic idea is that, when something goes wrong, it's communicated directly to the chat channel versus just to a log somewhere for later analysis.

Logging is an important part of the app development/maintenance cycle. It’s not just about the data you log, but also about how you do it. In this article, we are going to explore the Monolog package and see how it can help us take advantage of our logs.

They start by helping you get Monolog installed in your project via Composer and how to create their "general" logger. He then explains the use of "handlers" in the Monolog system and how to add them to the logger instance. They also explain Monolog's "bubbling" of messages in a browser/error log example. Next they show how to integrate the SlackHandler into the logger, providing it with an access token, the channel to send to and a name to log in with. The article also shows how to format the message, giving it a bit nicer look than just the standard text error. Finally they touch on preprocessors that can add extra information to the log messages without having to touch every instance where it's used.

tagged: monolog slack integration message error realtime chat introduction

Link: http://www.sitepoint.com/logging-with-monolog-from-devtools-to-slack/

PHP 7 Up and Running (Video Series)
Aug 28, 2015 @ 10:38:14

The Laracasts site has posted a set of videos that can help you learn all about PHP7 and get you up to speed before this next major release is available for download (well, a stable release anyway).

Slated for release in October, 2015, PHP 7 brings a wealth of new features, bug fixes, and performance improvements. If you're curious, come with me, as I demonstrate what's new!

The videos cover some of the major new features coming to the language including:

More videos are coming too, including one already listed showing how to use anonymous classes. Keep an eye on this series to learn all about PHP 7 before it's even released.

tagged: php7 video series introduction major version tutorial

Link: https://laracasts.com/series/php7-up-and-running