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

SitePoint PHP Blog:
How Privileged Are Programmers? Are You a John, Too?
Apr 25, 2017 @ 09:31:16

On the SitePoint PHP blog Christopher Pitt has written up a new article, a story about "John" a developer caricature that's all too familiar in the development world and how you can grow up from "being a John". It's all based on Christopher's own experiences too.

John was a developer. To be specific, he was a young, white, straight, young, self-taught developer. He wasn’t rare, but he was special. John grew up with a couple parents, who paid for everything he needed.

[...] John got average grades, but it was ok because [according to mum]; “he’s just bored of schooling, and too clever”. He walked right out of high-school and into a programming job. The pay wasn’t great; only enough for a small apartment and modest groceries [for one]. In time he’d earn more. [...] Over the years, John quickly got bored of programming. He loved the thought of the career, but it was all so boring. He moved jobs every year or so, and only then when his idiot bosses stopped seeing how much he mattered to their company.

He talks about his own past, how he realized he was a "John" and how he made the conscious decision to grow up and out of that situation. He talks about those being born into comfort and how they're not always forced to grow up or to really struggle. He mentions other common "John" points of view ("we can always just move jobs" or "meetings are just a distraction"). He's angry with himself for seeing so much of his previous life in these examples. He's also angry to see these same patterns in other developers around him, other "Johns" that treat him the same way with excuses, failed promises and delays.

I think of all these clever little things I could do, to force John to work. All these processes and mantras and check-lists. Then I despair. The only thing that’s going to make John realise he is wasting away is wasting away enough to fall through his safety net. He’s going to have to grow up on his own, and maybe then he’ll pay it forward to his future employers and clients.
tagged: john programmer privilege example opinion experience

Link: https://www.sitepoint.com/how-privileged-are-programmers-are-you-a-john-too/

Community News:
Latest PECL Releases (04.25.2017)
Apr 25, 2017 @ 08:05:02

Latest PECL Releases:

  • v8js 1.4.0
    Correctly initialize V8's ICU component

    • path to libv8 library is now baked into the library to find icudtl.dat file
    • if icudtl.dat file is moved after compile time, set v8js.icudtl_dat_path php.ini variable
  • v8 0.1.4
    This release adds low-level optimizations, simplify some internal methods and fix few bugs. For more details see change list below.

    As of this release, V8 >= 6.0.45 required.

      • BC-breaking or potentially BC-breaking changes

    Changes to public API and other important changes which may affect end-user:

    - Raise libv8 required version to 6.0.45;
    - Add V8Value::InstanceOf() method;
    - Add V8ObjectValue::SetNativeDataProperty() method;
    - Add V8PropertyFilter, V8KeyCollectionMode and V8IndexFilter enums;
    - Add property filtering support to V8ObjectValue::Get{Property,OwnProperty}Names();
    - Consistently expose all well-known symbols on V8SymbolValue;
    - Setting boolean props on StackFrame with valid type;
    - Remove non-working and non-supporting $attributes argument from V8StringValue constructor in stubs;
    - * Add V8ConstructorBehavior and support for it in V8FunctionTemplate constructor;
    - * Add signature support in V8FunctionTemplate constructor via $receiver;
    - * Add signature support to Template:SetNativeDataProperty() and ObjectTemplate::SetAccessor() via $receiver;
    - * Remove require $isolate parameter from V8Value::TypeOf();
    - * Remove deprecated V8Context::EstimatedSize() method;
    - * Remove deprecated V8StackTraceStackTraceOptions;
    - * Remove deprecated V8StackTrace::AsArray();
    - * Require Context explicitly in V8Isolate::ThrowException();
    - * Rename V8ExceptionsGenericException to V8ExceptionsException;
    - * Rename V8ExceptionsAbstractResourceLimitException to V8ExceptionsResourceLimitException;
    - internal: Check whether returned context is empty in V8IsolateGetEnteredContext() instead of checking InContext();


Gundars Meness:
Unit Testing - The Big Picture
Apr 24, 2017 @ 11:56:50

If you're still new to the world of testing in your applications, you should give this new guide from Gundars Meness a read. He's done a great job of providing "the big picture" of testing - why to do it and what it is.

This is not a crash course of what characters one needs to type in his code editor to produce unit tests. This is fuel the brain requires before attempting such actions.

The subject of Unit Testing is not as simple as one might think. Many of us, developers, go into unit testing based on pressure from clients, peers, colleagues, our heroes and so on. We quickly learn the value of it, and, once the tech setup is done, there is a tendency to forget the big picture, if it was ever learnt. This article will provide a short insight into what is and isn’t unit testing in PHP and in general, and unit test place in the quality assurance realm.

He then breaks up the article into a few different sections, each with a paragraph or two, covering different testing related topics:

  • What is testing?
  • What really is testing?
  • What is Unit Testing?
  • How to write a Unit test?

There's some great suggestions in here, for both those new to testing and those still trying to figure out some good practices.

tagged: unittest introduction bigpicture testing

Link: http://gundars.me/php/unit-testing-php-big-picture/

Freek van der Herten:
Dropbox will turn off v1 of their API soon. It’s time to update your PHP appli
Apr 24, 2017 @ 10:12:59

Freek van der Herten has a new post with both a reminder and a solution to an upcoming change from the Dropbox service: the disabling of their v1 API (and a PHP package you can use to be prepared).

Last year on 28th of June Dropbox deprecated v1 of their API. On the same date this year they will turn off all v1 endpoints. If you’re using using Flysystem, Laravel or the official PHP SDK to work with Dropbox, it’s the time to update.

Last week my company released a Dropbox API client and a Flysystem Dropbox adapter that both use v2 of the dropbox API. In this blogpost I’d like to explain how to install and use these packages.

He then shows you how to update your Flysystem adapters to use this new adapter for Dropbox - basically a simple code change once the package is installed. He then moves on to updating a Laravel application, configuring it's built-in file abstraction with the new adapter via a DropboxServiceProvider. The post ends with a bit talking about the update of other types of PHP applications (not using Flysystem) that could make use of other packages to make the required updates.

tagged: dropbox v1 adapter flysystem laravel tutorial update package

Link: https://murze.be/2017/04/dropbox-will-turn-off-v1-of-their-api-soon-its-time-to-update-your-php-application/

Amazon Web Services:
PHP application logging with Amazon CloudWatch Logs and Monolog
Apr 24, 2017 @ 09:46:47

On the Amazon Web Services blog there's a new post showing you how to use the Monolog logging library and a custom AWS extension to ship your logs to Amazon CloudWatch quickly and easily.

Logging and information debugging can be approached from a multitude of different angles. Whether you use an application framework or coding from scratch it’s always comforting to have familiar components and tools across different projects. In our examples today, I am going to enable Amazon CloudWatch Logs logging with a PHP application. To accomplish this, I wanted to use an existing solution that is both already popular and well used, and that is standards compliant. For these reasons, we are going to use the open source log library, PHP Monolog (https://github.com/Seldaek/monolog).

They start by introducing the Monolog library for those not familiar with it and how it relates to the PSR-3 standard. The ultimate goal with their implementation is to allow for the logs to be shipped to CloudWatch and implement some alerting around them. The tutorial then kicks in and they show you how to use Composer to install Monolog and an add-on to interface with CloudWatch. Code is provided to set up the initial logger and how to have it to log messages to different places. They then move over to CloudWatch and define a filter for the JSON data to find successful logins to your application. They also show how to use this same functionality in a Laravel application, contained in a test route.

tagged: aws amazon logging cloudwatch monolog tutorial install usage filter

Link: https://aws.amazon.com/blogs/developer/php-application-logging-with-amazon-cloudwatch-logs-and-monolog/

Stefan Koopmanschap:
To Exception or not to Exception
Apr 21, 2017 @ 16:21:47

In the latest post to his site Stefan Koopmanschap offers some advice on when to use exceptions and when to avoid them (the result of a recent Twitter discussion).

I recently found myself in a discussion on whether or not exceptions could be used to control program flow in software (specifically in PHP applications). That triggered me to post a tweet:

Exceptions should not be used to control expected application flow. Discuss.... @skoop

This triggered quite a bit of discussion, which gave me a lot of input on this topic. I want to thank everyone who joined that discussion for their input, which was really valuable. In this blogpost I'll do a summary of the different arguments in the discussion, and give my opinion on this.

He goes on to define the term "program flow" and how that relates to the idea of using exceptions to control it. He then talks about naming things, the "intent" of your code and how the right names can make your code clearer and easier to maintain.

tagged: exception flow program naming opinion

Link: https://leftontheweb.com/blog/2017/04/21/to-exception-or-not-to-exception/

How to Create a Laravel Helper
Apr 21, 2017 @ 15:15:28

On the NetTuts.com site there's a new tutorial from author Sajal Soni showing you how to create a custom Laravel helper, a set of helper functions that can be used through out the entire application.

Laravel includes a variety of global "helper" PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient. So, basically, helpers in Laravel are built-in utility functions that you can call from anywhere within your application. If they hadn't been provided by the core framework, you might have ended up developing your own helper classes.

Although the core provides a variety of helpers already, there’s always a chance that you’ll need your own and would like to develop one so you don’t have to repeat the same code here and there, thus enforcing better maintainability. You'll learn how to create a custom Laravel helper in this tutorial.

They start by talking about some of the current helpers and the functionality they relate to (arrays, paths, strings, etc). It then goes into the creation of the custom helper including the skeleton of the code layout, where to place them and how to load them into the application via a service provider.

tagged: custom laravel helper function creation tutorial

Link: https://code.tutsplus.com/tutorials/how-to-create-a-laravel-helper--cms-28537

QaFoo Blog:
How You Can Successfully Ship New Code in a Legacy Codebase
Apr 21, 2017 @ 13:39:13

On the QaFoo blog there's a new post sharing some ideas on how you can add new code to a legacy application and ship it successfully without too much interruption to the current code.

Usually the problems software needs to solve get more complex over time. As the software itself needs to model this increased complexity it is often necessary to replace entire subsystems with more efficient or flexible solutions. Instead of starting from scratch whenever this happens (often!), a better solution is to refactor the existing code and therefore reducing the risk of losing existing business rules and knowledge.

[...] Instead of introducing a long running branch in your version control system (VCS) where you spend days and months of refactoring, you instead introduce an abstraction in your code-base and implement the branching part by selecting different implementations of this abstraction at runtime.

They then give a few examples of methods that can be use to get the new code in:

  • Replacing the Backend in a CMS
  • Rewriting a submodule without changing public API
  • Github reimplements Merge button

The final point is broken down into the process they recommend including the refactor of the current code, starting in on the new implementation and deleting the old code.

tagged: refactor ship new code legacy application tutorial

Link: https://qafoo.com/blog/101_branch_by_abstraction.html

SitePoint PHP Blog:
Getting to Know and Love Xdebug
Apr 20, 2017 @ 17:55:59

On the SitePoint PHP blog editor Bruno Skvorc has posted a tutorial introducing you to Xdebug, the powerful debugging tool for PHP applications.

It’s been 15 years since Xdebug first came out. We think this is the perfect opportunity to re-introduce it to the world, and explain how and why it does what it does. Xdebug is a PHP extension (meaning it needs to be compiled and installed into a PHP installation) which provides the developer with some features for debugging.

It starts off by explaining some of the functionality that Xdebug brings to your debugging practices and the features that can help make it flow a little easier. It talks about how it differs from some of the IDE debugging tools and services like Blackfire.io. Next up is the example putting it to use and what the resulting errors look like. The post then gets into the integration of Vagrant with PhpStorm, using the profiler and how to force the rendering in Laravel output (it normally overrides the exception output with its own formatting).

tagged: tutorial know love xdebug introduction php debug debugging

Link: https://www.sitepoint.com/getting-know-love-xdebug/