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

Tomas Votruba:
How to Manage Configuration in Symfony without Bundle, Extension, and Configuration?
Nov 30, 2018 @ 12:55:07

In this new post to his site Tomas Votruba shows how to configure a Symfony application without using the bundle or extension configurations.

Symfony Flex is moving towards of bundle-less applications. That doesn't mean you should create a monolith code in /src as fast as possible, but rather control everything via .yaml and .env files. It's takes few steps to remove extension and move to import of services.yaml.

But how would you approach a simple task as setup a account number parameter?

For those not familiar with "no-bundle applications" in Symfony, he starts with a link to the SymfonyCast course listing out the main points. Following this he covers what changes in the service registration and what changes in the configuration (with code examples). He then provides some options including keeping the extension, setting the parameter manually and binding the parameter, favoring the last two on his list as more maintainable.

tagged: tutorial symfony configuration bundle extension management

Link: https://www.tomasvotruba.cz/blog/2018/11/29/how-to-manage-configuration-in-symfony-without-bundle-extension-and-configuraiton/

Matthias Noback:
Final classes by default, why?
Sep 12, 2018 @ 12:08:54

In this post to his site Matthias Noback makes the argument that, during your normal development, classes should be final by default and only changed if there's a need to extend them.

I recently wrote about when to add an interface to a class. After explaining good reasons for adding an interface, I claim that if none of those reasons apply in your situation, you should just use a class and declare it "final".

[...] For a couple of years now I've been using the final keyword everywhere (thanks to Marco Pivetta for <a href="https://ocramius.github.io/blog/when-to-declare-classes-final/>getting me on track!). When I see a class that's not final, it feels to me like it's a very vulnerable class. Its internals are out in the open; people can do with it what they want, not only what its creator has imagined.

Still, I also remember my initial resistance to adding final to every class definition, and I often have to defend myself during workshops, so I thought it would help if I explained all about it here.

He starts off by talking about the alternative - non-final classes - and some of the issues that can come with it (and class extension). He makes the suggestion that "replacing is better than overriding" and creates less complexity overall. He also answers a question about the use of the "Template Method" design pattern that would allow for improvement from base "skeleton" logic designed to be extended. He covers "composition over inheritance", the use case of extension and how "final" is a better direction.

tagged: final class exposure extension opinion override template composition

Link: https://matthiasnoback.nl/2018/09/final-classes-by-default-why/

php[architect]:
MySQL Without The SQL - Oh My!
Jul 13, 2018 @ 10:29:17

On the php[architect] site they've posted a full article from their July 2018 issue sharing information about a new kind of data store in MySQL.

Do you work on projects where you begin coding before knowing what your data looks like? Or are you part of the vast majority of developers who have had little or no training in database theory, relational calculus, Structured Query Language, or sets? Could you be working on a project without a database administrator to set up relational tables, indexes, and schemas? Or are you tired of embedding ugly lines of SQL in your pristine PHP code? There is new hope for you.

In the article Dave Stokes (of MySQL/Oracle) covers the new native JSON data type that was added in MySQL 5.7 but enhanced in MySQL 8 as a document store. He shows how to use this new functionality from the command line, what a "document" is and how to install and use the X DevAPI PECL extension to make use of it from your PHP code.

tagged: mysql datastore json tutorial pecl extension

Link: https://www.phparch.com/2018/07/mysql-without-the-sql-oh-my/

Remi Collet:
PHP extensions status with upcoming PHP 7.3
Jul 05, 2018 @ 12:22:19

With each new major version of the PHP language comes a long list of changes. Along with these changes can come breakage with software that's not a direct part of the PHP core (or extensions). In this post to his site Remi Collet lists out a large number of the more popular PHP extensions and, along with the specific version numbers, breaks down which will work and which won't.

He actually has three lists: "compatible", "work in progress" and "not compatible for now". Fortunately, the "compatible" list is the longest and includes:

There's also a pretty sizable list for the "work in progress" category, most of which are already in the "fixed upstream" category or have pull requests waiting for review to fix issues that were found. Most of the items in the "not compatible" list are either projects that are out of date or have moved away from the PECL extension approach to something more based in user-land code.

tagged: extension php73 compatibility list fixed pending wontfix

Link: https://blog.remirepo.net/post/2018/07/02/PHP-extensions-status-with-upcoming-PHP-7.3

Vladimir Goncharov:
Computer vision and machine learning in PHP using the opencv library
Jun 22, 2018 @ 12:02:15

Vladimir Goncharov has a tutorial posted to his Medium.com site showing how to integrate machine learning and computer vision into a PHP application using the opencv library. The php-opencv library is a C-level implementation (via an extension) making it easer to use it directly from PHP.

Now, “Machine learning” is developing very fast, it has already written a lot of articles, including the ones on the medium, and almost every developer would like to start using it in their work tasks and home projects, but where to start and what to use is not always understandable. Most articles for beginners offer a bunch of literature, on the reading of which there is not enough life, “inexpensive” courses, etc.

[...] I was considering writing a php-opencv module by myself using SWIG and spent a lot of time on it, but I did not achieve anything. [...] Then I found the library of php-opencv on the github space, it is a module for php7, which makes calls to opencv methods.

He then starts in on the code making use of the library to read in images, perform face detection, facial recognition, and locating facial marks/landmarks. He also includes a section covering the use of neural networks to improve the quality of images, classify them and the use of Tensorflow models to detect certain kinds of objects. The post ends with a look at getting the requirements installed to use the tool and links to other examples.

tagged: computer vision machine learning opencv library tutorial extension

Link: https://medium.com/@morozovsk/computer-vision-and-machine-learning-in-php-using-the-opencv-library-3131fe9df94b

Laravel News:
Speed Up Laravel on Top of Swoole
May 07, 2018 @ 10:47:09

On the Laravel News site there's a tutorial posted showing you how to use the Swole extension to speed up your Laravel-based application. Swole is a PHP extension written in C that provides missing asynchronous functionality to the language.

Swoole is a production-grade async programming framework for PHP. It is a PHP extension written in pure C language, which enables PHP developers to write high-performance, scalable, concurrent TCP, UDP, Unix socket, HTTP, WebSocket services in PHP without too much knowledge of the non-blocking I/O programming and low-level Linux kernel. You can think of Swoole as something like NodeJS but for PHP, with higher performance.

The post covers the "why?" question of using Swoole with Laravel, explaining how the traditional PHP request flow works. Swoole provides a way to reduce come of this processing overhead and increase performance. They then help you integrate Swoole and Laravel using a custom package (swooletw/laravel-swoole), installing both the package and using PECL to install the Swoole extension. Once the extension is enabled and the service provider is added, all it takes is an artisan command to start the web server up.

The post finishes with some quick benchmarks using wrk comparing it against a typical Nginx setup with PHP-FPM. Not surprisingly, Swoole outperforms the other setup well.

tagged: laravel swoole extension performance tutorial package install

Link: https://laravel-news.com/laravel-swoole

Zend Framework Blog:
Async Expressive? Try Swoole!
Mar 22, 2018 @ 09:28:22

On the Zend Framework blog there's a new tutorial posted that wants to help you use Expressive for asynchronous request handling with the help of the Swoole extension.

When we were finalizing features for Expressive 3, we had a number of users testing using asynchronous PHP web servers. As a result, we made a number of changes in the last few iterations to ensure that Expressive will work well under these paradigms.

Specifically, we made changes to how response prototypes are injected into services.

The article starts by talking about the issue with the previous response prototype handling, mostly that, in an async world, all responses would be sharing the same instance rather than rebuilding a new one for each request. It then explains their reasoning behind even worrying about async support in the framework's response handling noting that the major reason had to do with the performance gain. The post mentions the Swoole extension and shows how to install it via PECL but you'll need to check out the project's documentation to see how to create a server that makes use of it.

tagged: asynchronous swoole extension zendframework zendexpressive v3

Link: https://framework.zend.com/blog/2018-03-21-expressive-swoole.html

Derick Rethans:
Analemmas
Mar 06, 2018 @ 10:28:20

In a new post to his site Derick Rethans talks about "analemmas" and shows how to use PHP's own DateTime handling to determine the locations of the sun at different intervals (that's what an "analemma" tracks).

Last week I listened to an The Sceptics' Guide to the Universe where the word of the week was "But as I am currently starting to update the Guide to Date and Time Programming for a second edition, I was wondering whether I could create an analemma from existing PHP functions. Unfortunately, PHP only provides functionality to calculate when the Sun is at its highest point, through date_sun_info().

He includes an example of this function in use to determine the time the sun was at its zenith. While PHP by itself can't calculate the position, Derick remembered a PHP extension he wrote that could help: php-solarsystem. He includes some code using this functionality to iterate and locate the sun via its azimuth and altitude based on his choice of location (London). The result is a CSV export of data that he then drops in to gnuplot to create the graph of the analemma during that time.

tagged: analemma sun location diagram extension tutorial datetime graph calculate

Link: https://derickrethans.nl/analemma.html

Caleb Porzio:
My VS Code Setup
Dec 14, 2017 @ 09:53:50

Caleb Porzio has put together a post for those out there either considering using Microsoft's Visual Code Studio IDE or just want to see what it would be like for PHP development. In his post he shares his setup since making the switch over to the IDE full time.

I’m using VS Code as my primary editor these days and am really digging it. My setup is by no means perfect, but I've made lots of little tweaks along the way that you may benefit from.

I've set up these nifty categories, so feel free to jump around and try stuff out as you go, or come back later and use it as a reference.

Categories in the post include useful extensions, "must-have" settings, changing up the look and useful keybindings. There's plenty of links, output examples, screenshots of the IDE and the configuration options you'll need to change to update the settings to match his.

tagged: visualstudiocode vscode ide setup configuration extension setting

Link: http://calebporzio.com/my-vs-code-setup-2/

Pawel Mikolajczuk:
Create custom Twig node and parser
Aug 28, 2017 @ 09:16:47

On his Mdeium.com site Pawel Mikolajczuk has written up a post showing you how to create a custom Twig node and parser to extend the powerful functionality already included in this popular PHP templating package.

If You want to create custom twig node then this tutorial is for You. I will show you step by step how to create custom twig syntax (DSL) called gimme (we build it for our Superdesk Publisher project).

He starts with the required changes to your composer.json file to pull Twig in and a sample index.php file to build the Twig instance and add in the new extension (the "gimmie" handling). He then provides the code needed to create the extension based on Twig_Extension for the new node type. Next is an example of the "gimmie" handling in action in a template, dumping out the user information when the article is requested. He explains what each part of the tag is doing and shares the code to create the parser for its contents. Finally he shares the code required to create the "node" class, converting it over to its parsed PHP equivalent.

tagged: tutorial twig template custom node tag gimmie extension

Link: https://medium.com/@pawel.mikolajczuk/create-custom-twig-node-and-parser-b9cc056102ee