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

Sound of Symfony Podcast:
Episode 18 - Event sourcing
Jul 25, 2017 @ 12:51:49

The Sound of Symfony podcast, with hosts Magnus Nordlander and Tobias Nyholm, recently posted their latest episode - Episode #18: Event Sourcing.

In this episode we talk a little bit about Webpack Encore, and a lot about Event Sourcing, with our guest, Beau Simensen.

Other topics mentioned in this show include:

  • Beau's Domain-driven design book
  • Event sourcing libraries like EventCentric, Broadway and Prooph
  • Conferences like SymfonyLive and SymfonyCon Romania

You can listen to this latest episode either using the in-page audio player or by downloading the mp3 directly. If you enjoy the show you can subscribe to their feed and follow them on Twitter to get updates when new shows are released.

tagged: soundofsymfony podcast ep18 eventsourcing event beausimensen

Link: http://www.soundofsymfony.com/episode/episode-18/

thePHP.cc:
Don't call instance methods statically
Jul 25, 2017 @ 11:16:39

In this new post on thePHP.cc site they talk about calling instance methods statically, more specifically that it should be avoided.

There are quite a few things in PHP 4 that were a bit strange. One example is that PHP 4 allowed static calling of instance methods. [...] To keep backwards compatibility with PHP 4, this code works up to PHP 5, even though [the method in the example[ is not declared static.

[...] Now things will get really weird. When calling an instance method of another class statically, the $this context would carry over from the caller to the called class. In other words, $this suddenly refers to another object instance. While in PHP 5, this used to be an E_STRICT error, PHP 7 will emit an E_DEPRECATED error.

They point out that, while this is definitely odd behavior that shouldn't exist, it hasn't been removed because of PHP's backwards compatibility principles and only removing functionality like this in major versions. So, instead, they recommend calling all non-static methods using an instance of the class injected rather than directly calling them.

tagged: instance method call static object avoid error

Link: https://thephp.cc/news/2017/07/dont-call-instance-methods-statically

Alejandro Celaya:
Reusing factories in Zend ServiceManager
Jul 25, 2017 @ 10:03:33

Alejandro Celaya has a new post to his site showing the Zend Framework users out there how you can reuse factories in Zend/ServiceManager. Factories are heavily utilized by the component to create the objects the service returns. Factories tend to be single-use, however, but Alejandro has shown a way around that.

I like zend-servicemanager because it is explicit, and you are always in control of what's done, without loosing flexibility in the process. Since this container expects you to define factories for every service, you usually end up writing, testing and maintaining a lot of factories that doesn't add value to the application.

That's why it is so important to properly reuse factories when possible, not only because you will have to maintain less classes, but because the ServiceManager will instantiate less objects at runtime when it can reuse a factory.

He then talks about ways you can set up shared factories in your application including the use of an abstract factory class or a concrete factory to return other dependencies required. He also shows how to use the ConfigAbstractFactory that allows for the injection of dependencies based on a configuration (similar to the "wiring" in other dependency injection containers). Finally he shows the use of the ReflectionBasedAbstractFactory that handles the injection in about the same way but instead of basing it on a configuration it uses PHP's own reflection to try to determine the class and autoload it into the current system.

tagged: factory zend servicemanager zendframework configuration reflection abstract tutorial

Link: https://blog.alejandrocelaya.com/2017/07/21/reusing-factories-in-zend-servicemanager/

Sammy Kaye Powers:
Writing tests for PHP source (Part 5 & 6)
Jul 25, 2017 @ 09:56:56

Sammy Kaye Powers has posted the latest parts in his series looking at testing the PHP language with phpt tests. So far he's helped you compile PHP from source, run the test suite, learn about the phpt files and debug failing tests. He continues the series with two new posts:

In the 5th part of his series he shows how to use the PHP gcov site to locate lines of code in the PHP language core that aren't tested yet, how to create a new test to cover it and generating a code coverage report to see how much you've tested. In Part 6 he shows you how to take what you've created and submit it back to the PHP project on GitHub as a Pull Request (no RFC needed) based on changes from your own forked repository.

tagged: series testing language phpt untested gcov source pullrequest

Link: https://www.sammyk.me/finding-untested-code-in-php-source-writing-tests-for-php-source

Community News:
Latest PECL Releases (07.25.2017)
Jul 25, 2017 @ 08:05:02

Latest PECL Releases:

  • ssh2 1.1.2
    - Version 1.1.2 is same as 1.1 except this release contains this changelog

    • Fixed bug #72988 (Libor M.)
    • Fixed bug #73198 (Langemeijer)
    • Fixed php_url_parse issue (Remi Collet)
    • fix Invalid write of size 1 (Remi Collet)
    • Fixed bug #73819 (Mitch Hagstrand)
    • Fixed bug #73410 (Mitch Hagstrand)
    • Travis CI (Mitch Hagstrand)
    • Various other fixes on PHP 7 code and code cleanup (Mitch Hagstrand, Libor M., Anatol Belski)
  • ref 0.4.4
    This release improves PHP 7.2 compatibility support

    Changelist:

    • Restore original referent obj handler when it is no longer tracked
  • ds 1.2.0
    - Vector's minimum and default capacity down from 10 to 8. - Map and Set's minimum and default capacity down from 16 to 8. - Hash function of arrays is now the length of the array, so O(1).
  • rar 4.0.0
    - Merge changes made to unrar up to version 5.5.6. - Support PHP 7.0 and PHP 7.1. - Added functions RarEntry::getRedirType(), RarEntry::isRedirectToDirectory() and RarEntry::getRedirTarget(), as well as the following constants on RarEntry: FSREDIR_UNIXSYMLINK, FSREDIR_WINSYMLINK, FSREDIR_JUNCTION, FSREDIR_HARDLINK and FSREDIR_FILECOPY. - Changed stat handler to return UTC time for creation, modification and access time (does not work reliably on Windows). - Fix cloning of RarArchive being allowed.
  • couchbase 2.3.4
    * PCBC-495: update user management APIs * PCBC-478: add tests for Error Map using CouchbaseMock
  • mustache 0.7.4
    - Mark release as stable - Change minimum version to 5.4.0
  • handlebars 0.8.2RC2
    - Mustache delimiter preprocessing support behind the compat flag - Property lookup now generates a closure from a method if the value of the property is null or does not exist to emulate the behaviour of javascript where functions and properties share a symbol table - only supported for PHP 7 or greater - Changed target handlebars.c version to 0.6.4
  • libsodium 2.0.3
    Requires at least php 7.0 and libsodium 1.0.9.
  • libsodium 2.0.4
    Requires at least php 7.0 and libsodium 1.0.9.
tagged:

Link:

Community News:
Latest PEAR Releases (07.24.2017)
Jul 24, 2017 @ 08:05:01

Latest PEAR Releases:

tagged:

Link:

Tomáš Votruba:
The Bulletproof Event Naming For Symfony Event Dispatcher
Jul 21, 2017 @ 12:39:28

In a recent post to his site Tomáš Votruba shares what he sees as a "bulletproof" event naming scheme for use with the Symfony event dispatcher component.

I wrote intro to SymfonyEventDispatcher and how to use it with simple event.

But when it comes to dispatching events, you can choose from 4 different ways. Which one to choose and why? Today I will show you pros and cons of them to make it easier for you.

He then breaks up the remainder of the post into the four suggestions, each with code examples and brief descriptions:

    1. Start with Stringly
    1. Group File with Events Names as Constants
    1. ...Constant Names in Particular Event Classes
    1. Class-based Event Naming

For each he also includes some "pros" and "cons" to help you select which one might work best for your usage. He ends by taking things "a step further" and sharing integrating a suggestion to remove an argument and simplify the code.

tagged: naming symfony event dispatcher event tutorial

Link: https://pehapkari.cz/blog/2017/07/12/the-bulletproof-event-naming-for-symfony-event-dispatcher/

Sammy Kaye Powers:
Writing tests for PHP source (Series)
Jul 21, 2017 @ 11:21:48

Sammy Kaye Powers has a series of posts over on his site introducing you to testing the PHP language with .phpt tests. So far he's introduced the topic, shown how to run the tests and debugging failing tests.

If you've ever wanted to get involved with PHP internals, writing tests is a great way to get your foot into the door. The tests are written in PHP so you don't even need to know C to get started.

Each of the posts also comes with a screencast, narrated by Sammy, showing the information presented in the tutorial:

There's more to come in the series as he still plans to teach about how to fix current tests and how to eventually create your own. Stay tuned to his site for more tutorials in the series.

tagged: test unittest phpt language source series part1 part2 part3 part4

Link: https://www.sammyk.me/compiling-php-from-source-writing-tests-for-php-source

Jakub Zalas:
Static analysis tools for PHP in a single docker image
Jul 21, 2017 @ 10:56:07

Jakub Zalas has a new post to his site sharing a Docker image he's created to help make static analysis for your PHP code simpler: the phpqa image.

As part of my job I often perform application reviews and code quality analysis for clients who wish to have their code base looked at by an independent company. Running static analysis tools is usually a starting point to the review as it gives a general overview of a state of the project. I also like to run those tools as part of an introduction to an inherited code base.

For an easy access to the most popular static analysis tools for PHP I recently created a docker image - phpqa.

He lists out the tools that are included with the current version (a quite lengthy list) including:

  • analyze
  • box
  • deptrac
  • php-code-fixer
  • phpDocumentor
  • phpa
  • phploc
  • phpmd
  • phpstan
  • psalm

...and many more. Check out the full post for more of the tools in the list and links to more information about each one.

tagged: docker image static analysis tool image phpqa

Link: http://zalas.eu/phpqa-static-analysis-tools-for-php-docker-image/

Laravel News:
Two Best Laravel Packages to Manage Roles/Permissions
Jul 21, 2017 @ 09:48:46

The Laravel News site has posted an in-depth look at two packages Laravel users can implement to add in role/permission management: Bouncer and Laravel-permission.

Roles and permissions are an important part of many web applications. Laravel historically had a lot of packages for them, and improved the core code as well. So what is the situation on this market today? What packages are the best to use? I’ve picked two.

The post starts off by sharing a few reasons why you might even need these packages with the functionality that Laravel already includes. Most of the reasoning comes from the fact that the framework allows for checks but doesn't provide role/permission management. It then gets into what each of the package provide, how to install them and some example code to put them to use. It also looks at the database structure behind them and how they use that to store the authorization data.

tagged: laravel role permission package bouncer laravelpermission introduction tutorial

Link: https://laravel-news.com/two-best-roles-permissions-packages