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 (10.17.2018)
Oct 17, 2018 @ 08:05:02

Recent posts from the PHP Quickfix site:

tagged:

Link:

StarTutorial.com:
Modern PHP Developer - Iterator
Oct 16, 2018 @ 12:08:16

StarTutorial has continued their "Modern PHP Developer" series of tutorials with their latest covering the use of Iterators for working with sets of data.

If you have used a for loop in PHP, the idea of iteration is most likely not foreign to you. You pass an array to a for loop, and perform some logic inside the loop, but did you know that you can actually pass data structures other than arrays to a for loop? That's where Iterator comes into play.

The tutorial starts by introducing some of the basic concepts of what iterators are and how they're represented in PHP in their most basic form: arrays. They cover some of the basic array handing and functions before getting into the actual Iterator object handling. The article is then broken up into a few parts covering iterators and their functionality:

  • Your first iterator class
  • Why iterator?
  • SPL Iterators
  • ArrayObject vs SPL ArrayIterator
  • Iterating the File System
  • Peeking ahead with CachingIterator
  • Generator

Code and a summary of the functionality is included in each section providing you with a great start towards using iterators over simple arrays in your modern PHP applications.

tagged: developer tutorial introduction modern iterator

Link: https://www.startutorial.com/articles/view/modern-php-developer-iterator

TutsPlus.com:
Trigonometry, Random Numbers and More With Built-in PHP Math Functions
Oct 16, 2018 @ 11:56:01

The TutsPlus.com site has another great PHP tutorial for those new to the language covering mathematical functionality in the language, from the basics out to more complex topics like trigonometry and random number generation.

Basic maths is used a lot during programming. We need to frequently compare, add, multiply, subtract and divide different values when writing code.

Sometimes, the maths required in a program can be more involved. You might need to work with logarithmic, trigonometric or exponential functions. In this tutorial, I'll discuss how to use each of these functions in PHP, with examples.

This tutorial will introduce you to the built-in math functions in PHP for doing trigonometry, exponentiation, and logarithm calculations. We'll also look at rounding and generating random numbers.

They start off with some of the "heavy hitters" in PHP's math functionality and how how to perform trigonometric operations with the likes of sin, cos and tan. This is applied to create an interesting dynamic image using the GD functionality. Next up comes the exponential and logarithmic functions with simple examples followed by a section sharing some other useful math functions for more everyday needs.

tagged: tutorial math trigonometry random number introduction

Link: https://code.tutsplus.com/tutorials/mathematical-functions-in-php--cms-31972

Stitcher.io:
Laravel domains
Oct 16, 2018 @ 10:44:58

On the Sticher.io site there's a new tutorial posted where Brendt shares some thoughts about domain driven design and splitting codebases to make them more maintainable and logically separated.

In this post we'll look at a different approach of structuring large code bases into separate domains. The name "domain" is derived from the popular paradigm DDD, or also: domain driven design.

While many concepts in this post are inspired by DDD principles, they will not follow every rule set by the paradigm. In our context, "domain" can also be named "module". A "domain" simply refers to a category of related stuff, that's it.

The post then starts with a definition of what a "domain" is and how it relates to functionality in an application (a Laravel app in this case). He gives an example of restructuring the code into "domains" of functionality rather than thinking about their types (enums, rules, etc). He provides a new proposed directory structure for these domains including folders for Actions, Exceptions, Rules, Status and ValueObjects. He then walks through several of these categories and gives a bit more detail about what's inside and some of the functionality those files might contain.

tagged: domains laravel tutorial domaindrivendesign ddd restructure directory

Link: https://stitcher.io/blog/laravel-domains

PHP.net:
PHP 7.1.12 and 7.2.11 Released
Oct 16, 2018 @ 09:32:08

The main PHP.net site has announced the release of two new versions of PHP in the 7.1 and 7.2 series: PHP 7.1.23 and PHP 7.2.11.

The PHP development team announces the immediate availability of PHP 7.1.23 [and 7.2.11. This is a bugfix release.

All PHP 7.1 [and 7.2] users are encouraged to upgrade to this version.

Bugs fixed in theses releases include updates to the core language, the curl extension, opcaching, reflection functionality and the XMLRPC handling. If you're interested in all of the changes and want more detail, check out their respective Changelogs. As always, you can download these latest releases from the main downloads page or from the windows.php.net site.

tagged: language release php71 php72 bugfix

Link: http://php.net/archive/2018.php#id2018-10-11-3

Community News:
Latest PECL Releases (10.16.2018)
Oct 16, 2018 @ 08:05:02

Latest PECL Releases:

  • swoole 4.2.3
    This version is mostly based on the v4.2.2 made some fixes

    • Add Co::statvfs to retrieve file system information
    • Fixed non-array property error on swoole_http_response object
    • Fixed bad version number, add automated fixing tool
  • swoole 4.2.2
    + Task process supports asynchronous and coroutine + Refactor `addListener`, now developers can add new service listeners in any order + Support mixed server of `http`, `http2`, `websocket`, `tcp` + Completed coroutine redis client method parameter definition + `Co::readFile` supports reading non-disk files + Now static_handler supports more file types and skips files with length 0 * Fixed multipart/form-data in some cases parsing errors * Fixed the dislocation of sendfile data on MacOS * Fixed bug where SIGRTMIN processing error caused the log file to fail to reopen * Fixed a bug where redis-client last error value was not cleared and the next request was incorrect * Fixed a bug about connecting a connected asynchronous redis coredump * Fixed MySQL client protocol processing parameter binding NULL bug * Fixed segment fault caused by file hook, closed the include/require coroutine * Fixed the socket hook construct error * Fixed the sleep hook * Fixed a bug that returned an illegal pointer when reading an unset object property * Fixed the bug that after event_wait, EG(scope) is not restored in PHP70, causing private properties to be inaccessible * Alpine dependency compatibility optimization * Cygwin compatibility optimization * Support log_level to block warning information * Distinguish 204 response then skip body processing * The underlying code is cleaned up, all TSRM macros, PHP5 compatible macros and functions are removed, useless stack allocation and multiple pointers are reduced, FASTZPP is re-enabled to improve parameter parsing performance * Error tips optimization, error reporting guidelines will be generated when the underlying crash occurs
  • pledge 2.0.2
    - correct reflection information
  • libsodium 2.0.13
    - Security fix: sodium_pad() used to read extra memory when given an empty string
  • pledge 2.0.1
    - add unveil tests
  • redis 4.2.0RC1
    phpredis 4.2.0RC1

    The main feature of this release is new Streams API implemented by Michael Grunder.

    • Streams API [2c9e0572] (Michael Grunder)
    • Reset the socket after a timeout to make sure no wrong data is received [cd6ebc6d] (@marcdejonge)
    • Modify session testing logic [bfd27471] (Michael Grunder)
    • Allow '-' and '+' arguments and add tests for zLexCount and zRemRangeByLex [d4a08697] (Michael Grunder)
    • Fix printf format warnings [dcde9331] (Pavlo Yatsukhnenko)
    • Session module is required [58bd8cc8] (@remicollet)
    • Set default values for ini entries [e206ce9c] (Pavlo Yatsukhnenko)
    • Display ini entries in output of phpinfo [908ac4b3] (Pavlo Yatsukhnenko)
    • Persistant connections can be closed via close method + change reconnection logic [1d997873] (Pavlo Yatsukhnenko)
    • Documentation improvements (@mg, @elcheco, @lucascourot, @nolimitdev, Michael Grunder)
  • LuaSandbox 3.0.3
    - Fix ZTS build on PHP 7+ (Patch by Remi Collet)
tagged:

Link:

TutsPlus.com:
PHP Control Structures and Loops: if, else, for, foreach, while and More
Oct 15, 2018 @ 12:42:13

On the TutsPlus.com site today they're "getting back to basics" with a tutorial targeted at those just learning the PHP language. In this latest tutorial, they focus on control structures and loops such as if, else, for, foreach, while and more.

In simple terms, a control structure allows you to control the flow of code execution in your application. Generally, a program is executed sequentially, line by line, and a control structure allows you to alter that flow, usually depending on certain conditions.

Control structures are core features of the PHP language that allow your script to respond differently to different inputs or situations. This could allow your script to give different responses based on user input, file contents, or some other data.

They start with a flowchart showing the basic idea behind how flow control structures work and provide a more "real world" example of a user login. It then goes through each of the control structure types, providing a simple explanation of what it does, where it's useful and code examples of it in action.

tagged: control structure language tutorial beginner

Link: https://code.tutsplus.com/tutorials/php-control-structures-and-loops--cms-31999

Brandon Savage:
Avoiding Setter Injection
Oct 15, 2018 @ 11:11:38

Brandon Savage has a tutorial posted to his site covering the use of setter injection, some of the issues that can come with using it and how to avoid it.

PHP more or less has two kinds of dependency injection available: constructor injection, and setter injection. Constructor injection is the process of injecting dependencies through the constructor arguments. The dependencies are injected via the constructor, on object creation, and the object has them from the very beginning.

Setter injection is different; instead of providing the dependencies at construction time, the dependencies are provided via setter methods, once the object has been constructed. This allows the flexibility to configure the object during the runtime, rather than at construction.

He goes on to point out two flaws with setter injection: "half-baked" objects and the injection of potentially unused objects/resources. He spends the remainder of the post covering each of these topics more specifically and wraps it up with a recommendation to avoid it if possible and opt for useful, "fully baked" objects injected via the constructor instead.

tagged: tutorial avoid setter injection object halfbaked extra object resource

Link: https://www.brandonsavage.net/avoiding-setter-injection/

Frederick Vanbrabant:
The Integration Operation Segregation Principle
Oct 15, 2018 @ 10:48:13

In a new post to his site Frederick Vanbrabant tackles the integration operation segregation principle. While the term sounds intimidating, it's just a long way to say something you probably already do: refactor code into smaller testable chunks.

A few weeks ago I attended a DDDBelgium meetup where I was lucky to participate in a refactor workshop lead by Pim and Joop. After the incredible workshop Pim, Dries and me were discussing some code that we refactored earlier . Not so long in the conversation the words “Integration Operation Segregation Principle” casually got dropped by Pim.

Now I’m going, to be honest with you (as I was with them), I had no idea what the hell he was talking about. And maybe neither do you.

He starts with some simple code for a "calculator" class with a calculate method to handle the pricing of a rental car. He includes the test for the class/method as well, using a mock object and several expects calls to handle the method calls. The test ends up being larger than is probably good, so he looks into refactoring the original code to abstract out some of the functionality and make it more testable. In the process this also makes the code easier to follow and, while there is more of it, more maintainable and flexible in the end.

tagged: tutorial integration operation segregation principle refactor testable unittest

Link: https://frederickvanbrabant.com/post/2018-10-08-integration-operation-segregation-principle/

Matt Glaman:
Running Drupal's PHPUnit test suites on DDEV
Oct 15, 2018 @ 09:36:29

Matt Glaman has a new post to his site where he walks you through the setup and execution of Drupal's unit tests in the DDEV platform (a Docker-based project that makes it easy to get an environment up quickly).

DDEV is a local development stack built on top of Docker. It gives you all of your environment needs without messy configured on your host machine, without needing to know Docker or configure your own containers. Which is great, and makes life easier. Instead of just using DDEV to develop your site or application locally, why not also run your tests within it?

I have had quite a few people ask me how I configure my setup for testing with Drupal’s PHPUnit test suites. [...] All of these are the same reasons for using a virtual machine or containerized local development stack. So, it is fitting we run our tests within these local stacks as well!

In this article, part one of three, he assumes you already have a DDEV environment up and running with a Drupal application running inside (there's a guide here). With that in place, he shows how to configure PHPUnit via the phpunit.xml file, changing the "SIMPLETEST_*" values for the localhost and local DB connections. He shows how to run the tests by SSHing into the web Docker container and pointing PHPUnit at the configuration file. The end result should look something like this in a terminal.

tagged: tutorial series part1 drupal test unittest ddev docker testsuite

Link: https://glamanate.com/blog/running-drupals-phpunit-test-suites-ddev