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

Matthias Noback:
About fixtures
Jul 10, 2018 @ 10:21:05

Matthias Noback has written up an article on his site covering a tool that's common in many web applications, especially for testing: fixture data. In the post he makes some suggestions about effective ways to use them to provide more "real world" results for tests.

System and integration tests need database fixtures. These fixtures should be representative and diverse enough to "fake" normal usage of the application, so that the tests using them will catch any issues that might occur once you deploy the application to the production environment. There are many different options for dealing with fixtures; let's explore some of them.

He makes four suggestions of ways to handle fixtures:

  1. Generate them the "natural" way via interaction with the application and taking a snapshot of the data.
  2. Generate them at runtime for the tests, reloading them each time
  3. Manual insertion of custom data into the database for all tests
  4. Manual insertion of custom data into the database for each test case

He finishes the post by asking a question for those considering using fixture data: do you need them at all? Testing should be isolated from external sources so maybe they're not really needed...

tagged: fixtures list suggestions natural generate custom data database

Link: https://matthiasnoback.nl/2018/07/about-fixtures/

Tomas Votruba:
6 Reasons Why Doctrine is Alive and Kicking
Jul 10, 2018 @ 09:43:51

Tomas Vortuba has a new post to his site sharing a few reasons why he thinks that Doctrine isn't dead and is still "alive and kicking" with things still changing in the project.

Almost 1,5 year ago I wrote Why is Doctrine Dying. I didn't use dead, because it's is just state of time being. Open-source projects - like people - tend to find themselves on the top, being stuck or struggling with the right path from time to time. It's a completely normal process of evolution.

I don't know if that post helped it, but since then many things changed for better in Doctrine project. Saying that this post deprecates my old view and celebrate changes.

May this be an inspiration for open-source projects that find themselves stuck and the maintainers that find themselves unhappy.

His list includes reasons like:

  • Bump PHP 7.1 Without Waiting for Major Release
  • Cut the Weight to Save Yourself
  • From Talks and Post Evangelization to Code Improvements
  • New Release as a Baseline

For each point, he provides a little clarification and background from commits to the code and statistics about the community around the project.

tagged: doctrine project orm community alive reasons list

Link: https://www.tomasvotruba.cz/blog/2018/07/09/6-reasons-why-doctrine-is-alive-and-kicking/

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

Loïc Faugeron:
Short Identifier
Jun 22, 2018 @ 13:12:21

Loïc Faugeron has a post on his site covering the concept of short identifiers and covering some of the common types along with some of the downsides of the use of each.

Sometimes resources can be identified by one of their attributes (a name, title, slug) and sometimes they can't (no name, or confidential name). In the later case, an ID needs to be artificially crafted.

Two of the popular strategies is to use either an auto incremental one or a universally unique one, however when it comes to share them publicly, both strategies present some drawbacks

He lists several different types including:

  • Auto Incremental IDs
  • Short IDs
  • Hashes
  • Alphabetical representation

In the end, the method he recommends is hashing the ID value and using the first few characters (much the way you can refer to commit hashes in the Git version control tool).

tagged: short identifier list tutorial hash autoincrement shorten

Link: https://gnugat.github.io/2018/06/15/short-identifier.html

Exakat Blog:
The 100 PHP functions that you have to know
May 31, 2018 @ 09:54:33

On the Exakat blog they have a new post with the results from their evaluation of a wide range of PHP applications showing the Top 100 PHP functions in use.

Here is the top 100 PHP functions : it is the list of the most often used PHP native functions.

The functions are named, and ranked from 1 to 100. The other 4500 functions are not ranked now. The frequency column represents how often this function is used across PHP code : the reference corpus is a list of 1900 PHP open source projects. They were audited with Exakat static analysis engine, version 1.2.5. The average is the number of time a function is called within one project. Some function are used in isolation, and others are a staple.

The top 5 on the list are:

Each item on the list comes with "frequency" and "average" scores (that mostly relate directly). Check out the post for the full list and a list of some insights they worked up as they generated the listing.

tagged: top100 list function language ranking usage

Link: https://www.exakat.io/top-100-php-functions/

Laravel News:
Five Useful Laravel Blade Directives
May 23, 2018 @ 09:29:53

On the Laravel News site they've shared a list of five useful Blade directives that you may not have known about. Blade is the templating language included with the Laravel framework by default.

We’re going to look at five Laravel Blade directives you can use to simplify your templates, and learn about some convenient directives that make solving specific problems a cinch! If you’re new to the framework, these tips will help you discover the excellent features of Blade, Laravel’s templating engine.

The five on their list provide functionality to:

  1. Check if the user is authenticated
  2. Check if the user is a guest
  3. Include the first view if it exists or includes the second if it doesn’t
  4. Include a view based on a condition
  5. Include a view if it exists

Each one comes with example code showing it in use and a bit of explanation behind its use.

tagged: laravel directive blade template top5 list

Link: https://laravel-news.com/five-useful-laravel-blade-directives

Exakat Blog:
Weird operators in PHP
May 18, 2018 @ 09:56:29

On the Exakat blog there's a new post sharing some of the weird operators in PHP that you may have not known existed. These are ones outside of the normal = or . that can really do some odd things.

If you read the PHP documentation, you will learn about a ton of operators. If you haven’t learnt about PHP operators, go do that first, we’ll wait for you.

Operators are usually made up with strange symbols, like !, -, =>, <=>, ^ or ~. Really, some are plain readable like and, while some are merely an missed attempt at being readable, and actually hide a double personnality, like xor.

You probably think you know PHP’s documentation in and out, but there is always more to learn. So I dove deep into the core of PHP code, and looked some special PHP operators that are lesser known, but very useful in your daily coding.

There's ten of the odd operators on their list including:

  • the "b" operator for strings
  • the "left object" operator
  • constant names with * and %

Check out the full post for the details (and code examples) on each of these and more.

tagged: weird operator list language example

Link: https://www.exakat.io/weird-operators-in-php/

Ayesh Karunaratne:
What's new and changing in PHP 7.3
Apr 23, 2018 @ 10:40:01

Looking forward to the next larger release of the PHP language - PHP 7.3 - Ayesh Karunaratne has written up a post on his site sharing some of the new things that are coming and changes that will be made.

This is a live document (until PHP 7.3 is released as generally available) on changes and new features to expect in PHP 7.3, with code examples, relevant RFCs, and the rationale behind them, in their chronological order.

Currently there are five items on his list of features/changes approved and implemented for the 7.3 release:

  • Heredoc and Nowdoc syntax requirements are more relaxed
  • Allow trailing comma in function and method calls
  • Option to make json_encode and json_decode throw exceptions on errors
  • References in list()
  • Introduced is_countable() function

While each item is a link to the actual RFC with more detail, he spends the rest of the post going through each and briefly outlining what they offer and code examples of them in use.

tagged: php73 feature rfc changing new list

Link: https://ayesh.me/Upgrade-PHP-7.3

Laravel News:
20 Laravel Eloquent Tips and Tricks
Apr 16, 2018 @ 09:28:33

On the Laravel News site there's a new post sharing twenty Eloquent tips for the Laravel users out there.

Eloquent ORM seems like a simple mechanism, but under the hood, there’s a lot of semi-hidden functions and less-known ways to achieve more with it. In this article, I will show you a few tricks.

Among the tips and "hidden features" mentioned are tips about:

  • Increments and Decrements
  • Model boot() method
  • Model properties: timestamps, appends etc.
  • Order by relationship
  • Order by Mutator
  • Raw query methods
  • Create additional things when creating a model

...and many more. There's code examples for each of them showing them in use too.

tagged: laravel eloquent tips top20 list database orm

Link: https://laravel-news.com/eloquent-tips-tricks

Web Technologies Blog:
Code quality tools in PHP to check and improve your code
Apr 12, 2018 @ 10:52:55

On the Web Technologies blog they've posted a guide to some of the top PHP code quality assurance tools to ensure your codebase is kept neat, clear and clean from any unnecessary complexity.

You’ve got the good approach dear reader: code quality tools are essential to write solid and error-free PHP code. It can help your colleagues detect defects in the codebase and teach them some key concepts.

Don’t forget however that the advises and data they can provide won’t be appropriate everywhere. Your experience and your analysis skills are the one you should trust first.

The tutorial starts of with some of the tooling you'll need to get the system up and running: Composer for package management, terminal access for command execution and editor/IDE integrations (optional, obviously). It then lists out each of the tools and includes installation steps and links to more information:

  • PHP-CS-Fixer (PHP Coding Standards Fixer)
  • PHPCS (PHP CodeSniffer)
  • PHPMD (PHP Mess Detector)
  • PHPStan (PHP Static Analysis Tool)
  • PHPUnit and the CRAP metric

It also includes a few "bonus" tools that might be useful to track other quality aspects of your code including PhpLoc (lines of code), PHPMND for detecting "magic" numbers and churn-php for evaluating complexity of code based on number of commits. there's several more listed in the full post so be sure to check it out and see how you can integrate them into your development process.

tagged: quality assurance tool list improve code tutorial

Link: http://web-techno.net/code-quality-check-tools-php/