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

SitePoint PHP Blog:
3 More Joins You Should Be Familiar With
Feb 08, 2016 @ 12:18:36

On the SitePoint PHP blog Zach Wallace shares more database wisdom with his readers introducing three more JOINs you should know in your development work.

There are many ways to JOIN data from two database tables and filter the information you require. Craig Buckler wrote a popular piece on understanding JOINs; namely INNER, LEFT, RIGHT, and FULL OUTER. This article is an extension of that one.

He starts with the data he'll be working with: customers and books, linked by a book_id column. He then quickly reviews some of the joins already discussed in the previous article (LEFT, RIGHT, OUTER, INNER) before getting into the newer, more powerful types:

  • LEFT JOIN with Exclusion
  • RIGHT JOIN with Exclusion
  • OUTER JOIN with Exclusions

He finishes the post with a few other thoughts about using WHERE clauses in JOINs, the CROSS JOIN and how the JOINs relate to each other in MySQL.

tagged: join database three list inner outer left exclusion advanced example tutorial

Link: http://www.sitepoint.com/3-more-joins-you-should-be-familiar-with/

Michelangelo van Dam:
PHP Arrays - The php array functions
Feb 08, 2016 @ 11:51:02

Michelangelo Van Dam is back with another part of his series covering the use of arrays in PHP. In previous articles he covered some of the basics including operations and associative arrays but in this new post he moves up and talks about some of the other functions you can use to manipulate them even further.

In my previous article about arrays (the basics, simple operations and associative arrays or hash maps) I have shown what arrays are and what you can do with it. Now I want to dive into real fun and explain PHP's array functions with real-world examples and how you can apply them in your day-to-day work.

He then goes through several of the PHP array functions, providing simple code snippets of them in action. To help apply it to a more "real world" situation he uses data based on a "countries" table in a database, making use of the "iso" and "printable_name" columns:

This is only three of the many methods you can use in PHP to manipulate arrays but it gives you a taste of what's there and what's to come in his future articles.

tagged: array tutorial functions arraywalk arraymap arrayintersectkey

Link: http://www.dragonbe.com/2016/02/php-arrays-php-array-functions.html

Rob Allen:
PSR-7 file uploads in Slim 3
Feb 05, 2016 @ 11:08:23

In a post to his site Rob Allen explains how to handle file uploads in a PSR-7 structure, specifically illustrating with an example using the Slim (v3) framework.

Handling file uploads in Slim 3 is reasonably easy as it uses the PSR-7 Request object, so let's take a look.

He shows how to create a simple index route in a Slim application and render a view containing just a simple form with an upload field and submit button. When the form submits, he uses the getUploadedFiles method on the Slim Request object to get the file information for the upload. He also shows how to check for errors on the upload using the file data as an object and calling the getError method.

tagged: slim3 file upload tutorial handling error psr7 request

Link: https://akrabat.com/psr-7-file-uploads-in-slim-3/

Community News:
phpschool.io Announced
Feb 04, 2016 @ 12:45:55

A new service has launched in an effort to help teach PHP to those looking to learn in a different sort of way. The phpschool.io site provides you with a series of exercises that walk you through both the fundamentals of the language and a few more complex topics.

PHP School is a set of ever expanding workshops to teach you basic to advanced concepts in PHP. We launch with one workshop: Learn You PHP. [...] Each exercise increases in difficulty, guiding you through the core concepts of PHP.

Currently the tutorials cover topics like "My First IO", separation of concerns, working with exceptions and handling dependencies. The installation of the lessons is as simple as making a composer require call and installing the packages and dependencies required by the tool. They're also actively looking for community contributions to add more workshops to the based on the Learn You PHP package currently included. The training was inspired by what NodeSchool provides for the Node.js language.

tagged: phpschool learning training beginner language tutorial

Link: http://www.phpschool.io/

TutsPlus.com:
Test-Driven Development With Laravel & Doctrine
Feb 02, 2016 @ 13:39:47

On the TutsPlus.com site they've posted a new tutorial showing you how to do test-driven development with Laravel and Doctrine, making use of Doctrine's own testing functionality inside of a Laravel application for PHPUnit based unit testing.

As a PHP developer, you may use the Test-Driven Development (TDD) technique to develop your software by writing tests. Typically, TDD will divide each task of the development into individual units. A test is then written to ensure that the unit behaves as expected. [...] TDD verifies that the code does what you expect it to do. If something goes wrong, there are only a few lines of code to recheck. Mistakes are easy to find and fix. In TDD, the test focuses on the behavior, not the implementation. TDD provides proven code that has been tested, designed, and coded.

[...] PHPUnit is the de-facto standard for unit testing PHP. It’s essentially a framework for writing tests and providing the tools that you will need to run tests and analyze the results. PHPUnit derives its structure and functionality from Kent Beck’s SUnit.

He briefly talks about some of the assertions that PHPUnit has to offer before getting into the support that Laravel includes and how to configure it so Doctrine can work with your database. He then talks about Doctrine, briefly introducing the popular database abstraction tool and how to integrate it with a Laravel application. From there he starts in on the tests themselves, showing code that uses fixture data to create several tests for Post and Comment data.

tagged: testdriven development tdd laravel doctrine fixture tutorial

Link: http://code.tutsplus.com/tutorials/test-driven-development-with-laravel-doctrine--cms-25563

Ibuildings Blog:
Programming Guidelines - Part 3: The Life and Death of Objects
Feb 02, 2016 @ 11:42:05

The Ibuildings blog has posted the latest part of their series looking at some general programming guidelines and principles that can help you in your own development work. In this latest article Matthias Noback talks about the "life and death of objects" in more detail including creating, updating and how they "die".

In the first part of this series we looked at ways to reduce the complexity of function bodies. The second part covered several strategies for reducing complexity even more, by getting rid of null in our code. In this article we'll zoom out a bit and look at how to properly organize the lifecycle of our objects, from creating them to changing them, letting them pass away and bringing them back from the dead.

He starts with a brief list of things that are true about objects (they live in memory, they hide implementation, etc) and some of the issues with poor object handling. He then gets into some of the basics: creating objects (meaningful & different ways), validating the input to constructors and methods and changing them to update properties and related objects. He also suggests preferring immutable objects and talks about value objects to help towards this goal. Finally he talks about the death of objects and some of the ways you can possibly "bring them back to life".

tagged: oop object detail introduction validate immutable valueobject revive lifecycle tutorial

Link: https://www.ibuildings.nl/blog/2016/02/programming-guidelines-part-3-the-life-and-death-objects

Speedemy.com:
Troubleshooting (Web) Application Performance Issues with Strace
Feb 01, 2016 @ 11:51:21

On the Speedemy.com site there's a post showing you how to get down to a seriously low level of processing and identify performance issues with strace, the debugging tool that helps monitor interactions between processes, the kernel, system calls, etc.

What do you do when your Linux web app starts acting out? You troubleshoot it, of course! Me too. And today I would like to talk to you about one tool that works really well with all sorts of applications and application servers – ranging from apache http server running modules (mod_php, mod_perl, etc.), to applications running in fast cgi setting or even simple single-threaded programs.

The tool I’m talking about is strace, and if you’re not familiar with it, it will be my pleasure to introduce you two.

They start off by answering the question of when you shouldn't use strace for testing (like when an application can actually be profiled properly) before shows where it can actually help. The post then briefly introduces strace and what it can do, pointing out what kind of information it can provide. From there they start in on using it to do the debugging and show examples of the output it can provide. They help you use some other command line options to refine this output into something a bit more useful and even include an awk command to narrow it down even more .

tagged: strace performance issue application tutorial

Link: http://www.speedemy.com/troubleshooting-web-application-performance-issues/

Matthew Weier O'Phinney:
Automating GitHub Pages Builds with MkDocs
Feb 01, 2016 @ 10:49:57

In this new post to his site Matthew Weier O'Phinney details the process they (Zend) used to create the documentation for the latest release of their Expressive PSR-7 compatible framework (now in v1.0).

One of the final tasks in prepping for the Expressive 1.0 release was setting up the documentation site. We'd decided to use GitHub Pages for this, and we wanted to automate builds so that as we push to the master branch, documentation is deployed.

The process turned out both simple and bewilderingly difficult. This post is intended to help others in the same situation.

While they decided on MkDocs for the actual document generation (written in Python) Matthew how he integrated it with the builds they'd already created for the Expressive framework. He talks about reusability for the process, eventually using it again on the Zend Framework side. He also shows the full process for creating the resulting documentation and pushing it over to GitHub Pages including the setup of the credentials, which events should trigger the build and handling environment variables and software dependencies. It's a great post with plenty of details on each step of the process - I'd highly recommend it if you're looking into building these sorts of documents for your project.

tagged: github pages build travisci mkdocs python tutorial process

Link: https://mwop.net/blog/2016-01-29-automating-gh-pages.html

Symfony Finland:
What's on the Menu, Symfony?
Jan 28, 2016 @ 11:49:13

On the Symfony Finland site they've posted a tutorial about Symfony and menus, making use of the KnpMenuBundle to create flexible and easily configured menus with their own renderers.

Menus are a vital part of any web application or a website. Content Management Systems are traditionally a strong contender in this field as they are at their core just tools to create navigatable views to a pool of content. The Symfony Framework on the other hand is neutral when it comes to menus.

[...] There are a number of options for building menus in PHP, but the de-facto standard method for Symfony Framework is the KnpMenuBundle. It uses the KnpMenu library which is an object oriented PHP library for constructing and rendering menus.

The tutorial provides a simple example of using the bundle to create a menu with a handful of options and rendering it with a simple (included) ListRenderer. There's also an example of using a YAML configuration to create the menu and some example code of using a bit more complex and dynamic menu. They also talk a bit about content management systems, their use of menus and which they see as providing a better user experience than the others.

tagged: menu tutorial knpmenubundle symfony cms knplabs

Link: https://www.symfony.fi/entry/whats-on-the-menu-symfony

SitePoint PHP Blog:
Command Buses Demystified: A Look at the Tactician Package
Jan 27, 2016 @ 10:47:44

On the SitePoint PHP blog there's a tutorial posted that wants to help demystify the command bus design pattern with the help of the Tactician package, a part of the packages from The PHP League.

Command Buses have been getting a lot of community attention lately. The topic can be quite overwhelming at first when trying to understand all the concepts and terminology, but in essence – what a Command Bus does is actually incredibly simple.

In this article, we’ll take a closer look at variations of the Command Pattern; their components; what a Command Bus is; and an example application using the Tactician package.

The article starts with a look at what the Command Bus design pattern is and where it could be put to use in an application. There's a bit of sample code showing how to implement a basic bus and the commands it would be used to execute. Their example application uses a "deck of cards" set of actions. They show how to use the Tactician library to build and execute three related commands: CreateDeck, ShuffleDeck and DrawCard. They show you how to build out the pieces you'll need - the extractor, locator and middleware - and join them all together to execute the commands.

tagged: tutorial tactician package commandbus designpattern introduction

Link: http://www.sitepoint.com/command-buses-demystified-a-look-at-the-tactician-package/