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

Community News:
Recent posts from PHP Quickfix (03.29.2017)
Mar 29, 2017 @ 08:05:02

Recent posts from the PHP Quickfix site:

tagged:

Link:

Hackermoon.com:
Debugging a PHP application with strace
Mar 28, 2017 @ 11:24:43

On the Hackernoon.com site there's a recent post from Paolo Agostinetto showing you how to debug your PHP application with a different tool that most might use: strace.

Every once in a while it happens that you have a tricky bug, and when it does you risk to lose hours or even days fixing it.

[...] Yet, sometimes there is that one bug that makes you lose your shit after a whole afternoon spent looking for the root cause. In my experience, bugs that I introduce are generally very quick and easy to spot and fix. But the real challenge is finding bugs in other people’s code like third party libraries, PHP extensions or even PHP itself.

He then talks about a time when his situation was a bit different - he was getting 500 errors from his code that weren't being caught correctly by error handling. He found that Apache was out-of-memory-ing but debugging the exact cause (a suspect Doctrine query) would take more time. Instead he turned to strace and, with a bit of hunting in the resulting output, he tracked the issue down to XDebug being enabled (and a setting that was generating a memory leak).

tagged: debug application strace memory error xdebug process

Link: https://hackernoon.com/debugging-a-php-application-with-strace-4d0ae59f880b

Alejandro Celaya:
My thoughts after migrating some projects to Zend Expressive 2
Mar 28, 2017 @ 10:15:20

Alejandro Celaya has a new post to his site sharing some of his thoughts after migration applications to Zend Expressive 2 and some of his experiences along the way upgrading to this latest version.

The day Zend Expressive 2 was released I was super excited. I have been using it a lot for both professional and personal projects, so I'm quite used to it.

Since I've been using it in many projects, being able to update all of them to version 2 was a challenge, but I can say, I have succeed.

He talks about the projects themselves first, his own site at alejandrocelaya.com and shlink.io, and what kind of functionality they have. He then briefly covers the process to get them migrated and some of the changes he needed to make including:

  • adding an error hander
  • moving to the new error handling middleware strategy
  • using the support for interop middleware (single-pass)
  • small router changes due to using a custom router

He ends the post looking at the shift in programmatic approach Zend Expressive 2 uses (versus v1 handling) and changes he made to his middleware handling to reflect it.

tagged: zendexpressive2 zendexpressive upgrade application process changes

Link: https://blog.alejandrocelaya.com/2017/03/27/my-thoughts-after-migrating-some-projects-to-zend-expressive-2/

StackOverflow:
Developer Survey Results 2017
Mar 28, 2017 @ 09:46:14

Each year the StackOverflow site posts a survey for developers to record their current feelings, thoughts and background. They've posted the results for this year's survey with the results from over 64,000 developers worldwide.

Each year since 2011, Stack Overflow has asked developers about their favorite technologies, coding habits, and work preferences, as well as how they learn, share, and level up. This year represents the largest group of respondents in our history: 64,000 developers took our annual survey in January.

As the world’s largest and most trusted community of software developers, we run this survey and share these results to improve developers’ lives: We want to empower developers by providing them with rich information about themselves, their industry, and their peers. And we want to use this information to educate employers about who developers are and what they need.

They start by share some high level points they learned from this year's results. The remainder of the post is the results presented in a more easily consumable graph/chart form. You can, of course, download the data yourself if you're interested in running reports of your own.

tagged: stackoverflow developer survey results 2017

Link: https://stackoverflow.com/insights/survey/2017/

Community News:
Latest PECL Releases (03.28.2017)
Mar 28, 2017 @ 08:05:01

Latest PECL Releases:

  • event 2.3.0
    Fixed build errors with LibreSSL

  • dio 0.1.0
    - Fixed memory leak in dio_read (Dawid Zamirski) - Fixed Bug #74209 dio_stat - appended nulls (Remi)
  • redis 3.1.2
    phpredis 3.1.2
    • RedisArray segfault fix [564ce3] (Pavlo Yatsukhnenko)
    • Small memory leak fix [645888b] (Mike Grunder)
    • Segfault fix when recreating RedisCluster objects [abf7d4] (Michael Grunder)
    • Fix for RedisCluster bulk response parsing [4121c4] (Alberto Fern?ndez)
    • Re allow single array for sInterStore [6ef0c2, d01966] (Michael Grunder)
    • Better TravisCI integration [4fd2f6] (Pavlo Yatsukhnenko)
  • timezonedb 2017.2
    Updated to version 2017.2 (2017b)
  • ds 1.1.8
    - PriorityQueue automatic truncate bug #78 - Bugs related to unserialization. #77
  • win32service 0.2.0
    Update for PHP 7.0 and 7.1. The binary is available here: https://github.com/InExtenso/win32service/releases/tag/v0.2.0
tagged:

Link:

SitePoint PHP Blog:
Creating Strictly Typed Arrays and Collections in PHP
Mar 27, 2017 @ 12:45:06

On the SitePoint PHP blog there's a new post from Bert Ramakers showing you how to create strictly typed arrays and collections in PHP.

One of the language features announced back in PHP 5.6 was the addition of the ... token to denote that a function or method accepts a variable length of arguments.

Something I rarely see mentioned is that it’s possible to combine this feature with type hints to essentially create typed arrays.

He starts with an example of a class/method that only takes in a certain type of objects as a collection (using the "...") with a fatal thrown if anything else is given. He also shows how to do the same thing with scalar types and the "..." operator with a typed input. He does point out one problem with this approach, namely that if more complex input is required the single type just wouldn't work. His solution involves custom collection classes where the settings are in the collection and not passed directly into the method. This collection then contains some of the base functionality (like getting an average value from a set of floats) and can be enhanced with other typical interfaces to work like any other collection. He also presents another option: using value objects for validation of the input.

tagged: collection array strict typing tutorial operator

Link: https://www.sitepoint.com/creating-strictly-typed-arrays-collections-php/

PHPUgly Podcast:
Episode 54 - Tractor Hacking
Mar 27, 2017 @ 11:33:35

The PHPUgly podcast, hosted by Eric Van Johnson, Tom Rideout and John Congdon, has posted their latest episode: Episode #54: Tractor Hacking.

Topics mentioned in this episode include:

You can listen to this latest episode either using the in-page audio player, directly on SoundCloud or you can watch the video of the live recording over on YouTube. If you enjoy the show, be sure to subscribe to their feed and follow them on Twitter to get updates when new shows are released.

tagged: phpugly podcast ep54 tractor hack ericvanjohnson tomrideout johncongdon

Link: https://phpugly.com/blog/54tractor-hacking

Raphael Stolt:
Keeping your CLI integration tests green on Windows
Mar 27, 2017 @ 10:55:08

Raphael Stolt has a new post to his site for the PHP on Windows users out there helping you to keep your integration tests green when little things (like line ending differences) can cause issues between the Windows and unix-based platforms.

Lately on a Windows system, some failing integration tests for CLI commands utilising the Symfony Console component caused me some blip headaches by PHPUnit insisting that two strings are not identical due to different line endings. The following post documents the small steps I took to overcome these headaches.

He starts with the error message that the failing test was giving, a slightly unhelpful response with the "actual" and "expected" values looking basically the same. He suspected it to be something different with the encoding or line endings (a common issue between Windows and Linux platforms). To confirm his suspicions he looked deeper into the Symfony Console code and, on locating the difference, extended the "CommandTester" class to automatically disable the "decorated" setting across all tests.

tagged: phpunit testing integration green windows platform decorate tutorial

Link: http://raphaelstolt.blogspot.com/2017/03/keeping-your-cli-integration-tests.html

Nicola Malizia:
Understanding Laravel’s Automatic Facades
Mar 27, 2017 @ 09:24:36

On his Unnikked site Nicola Malizia has written up a post sharing some insight into how Laravel's automatic facades work, a feature that was introduced in Laravel v5.4.

Another cool feature shipped with the release of Laravel 5.4 is the ability to use Facades on the fly. Automatic Facades with the official documentation is quite informative. So I assume you are familiar with them.

He then starts in on the creation of custom facades: defining the functionality (a class), creating the facade and updating the app config to load it in. He then covers what's happening behind the scenes when the "Facades" namespace is loaded and the facade is called (lots of code snippets included here).

My suggestion is to start using automatic facades whenever is possible, their impact is negligible. To see when to use facades in general a good read is available in the official documentation.
tagged: laravel automatic facade tutorial introduction

Link: https://unnikked.ga/understanding-laravels-automatic-facades-d623e4774e5f#.hi2vq6igs

Benjamin Eberlei:
Explicit Global State with Context Objects
Mar 24, 2017 @ 11:50:12

In a post to his site Benjamin Eberlei looks at global state in PHP using something called "context objects" and how they can be used as an alternative to true global state.

Global State is considered bad for maintainability of software. Side effects on global state can cause a very nasty class of bugs. Context objects are one flavour of global state. For example, I remember that Symfony1 had a particularly nasty context object that was a global singleton containing references to very many services of the framework.

As with every concept in programming, there are no absolute truths though and there are many use-cases where context objects make sense. This blog posts tries to explain my reasons for using context objects.

He starts by getting everyone on the same page by defining a context - the "circumstances in which something can be fully understood". He then moves into the world of context objects, talking about how they encapsulate the information other objects need to execute. They're essentially "container" objects that allow for more control that something like the normal PHP superglobals. From there he helps you define what kind of context objects you might need in your application and provides a real-world example from his own experience at Tideways.

tagged: global state context object tutorial introduction definition

Link: https://beberlei.de/2017/03/12/explicit_global_state_with_context_objects.html