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

StarTutorial.com:
Modern PHP Developer - Composer
Sep 17, 2018 @ 12:07:01

On the StarTutorial.com site they've posted a tutorial for those that might be newer to the PHP language and ecosystem around it covering the use of Composer. In this latest tutorial they cover some of the basics of using this package manager to pull in and use dependencies in your PHP application.

In general, a block of code forms a method, a group of methods forms a class and a set of classes form a package. A reusable package can be dropped into any project and be used without any need to add functionality to it. A package exposes APIs for clients to achieve a single goal. Packages help our applications achieve DRY (Don't Repeat Yourself), a principle of software development, which reduces repetition of information of all kinds.

[...] In most cases, packages have dependencies. [...] We do need a package manager, a package manager that can solve all of these dependency headaches for us.

The tutorial then goes on to compare two of the main package managers in PHP: Composer and PEAR. It then walks through the installation of Composer and how to use it to pull in a package (in this case the "Faker" package for generating fake user data). It also explains the different commands and configuration files used in working with Composer.

tagged: tutorial introduction composer package manager development

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

CodeWall:
Debug PHP with XDebug on NetBeans
Sep 06, 2018 @ 09:35:21

On the Codewall.co.uk site they've posted another tutorial that will help you set up a part of your PHP development environment: XDebug and the IDE NetBeans.

NetBeans is a fantastic free IDE for not just PHP, but other languages like HTML, JavaScript, C++ and more. For PHP it comes highly prepared for being your predominant development environment. It has a whopping list of features that turbo-charge your programming like it’s auto-complete ability to name just one. A PHP development environment isn’t complete unless you have the power to debug the code you write, in this tutorial, you’ll learn how to correctly set that up.

After covering some of the prerequisites they break down the process into a few steps:

  • Download XDebug
  • Configuring XDebug in the PHP.ini file
  • Checking configuration has been activated
  • Configuring NetBeans to use the xDebug module

The last step in the process is an example of actually running the debugger and debugging some code with a breakpoint (and the resulting output)

tagged: tutorial ide netbeans xdebug debugging environment development

Link: https://www.codewall.co.uk/debug-php-with-xdebug-on-netbeans/

Colin O'Dell:
Automatically Switch PHP Version on cd
Aug 09, 2018 @ 10:48:31

Colin O'Dell has shared an interesting setup he's created to make it easier to switch between PHP versions when testing your code. In his latest post he shows how to switch the version "on cd" (directory change) with the help of some command line shell tooling.

After using phpbrew to manage my local PHP versions for a while, I got tired of re-compiling PHP after every release and decided to install multiple PHP versions side-by-side with Ond?ej Surý's PPA. One of the features I missed from phpbrew was the ability to run a command like phpbrew use php-7.2.8 to automatically change the php command to that version, so I ended up implementing this feature myself using symlinks and shell aliases.

He then walks through his end result, showing the modification of the default php symlink and aliases that can be used to dynamically switch its target. He then includes some examples of how to automate this using your application's PHP version requirements in the composer.json and a simple ZSH script that's triggered on directory change.

tagged: version development composer zsh commandline shell switch tutorial

Link: https://www.colinodell.com/blog/201808/automatically-switch-php-version-cd

Frederick Vanbrabant:
What Performance Tricks Actually Work
Jul 25, 2018 @ 09:55:24

Frederick Vanbrabant has a new post to his site sharing some performance tips you can integrate into your PHP code to help improve its overall processing time. He also talks some about a few that are just myths and debunks them.

We’ve all been there before, you submit a pull request and moments later you get a comment like: “Hey you should use a native function here, they are so much faster” or “You can declare this final, that way we save some processing power”.

It’s great that we as developers keep an eye on this, but how true are these thing. And are they still a thing in newer PHP versions?

He goes through a list of ten tricks that have been widely shared and creates some simple benchmarks around their use:

  • single versus double quotes
  • JSON handling versus XML handling
  • speed difference from using layered objects
  • native array functions versus loops
  • fetching an array item by quoted ID versus just ID
  • performance difference of throwing exceptions
  • impact of unused variables
  • magic methods versus normal methods
  • final versus non-final classes
  • comments in code

For each of the items in the list he includes the example code he used for the benchmark and the output from the PHPBench tool.

tagged: performance trick development tutorial

Link: https://frederickvanbrabant.com/2018/07/24/php-performance.html

Matthias Noback:
Testing actual behavior
Jun 26, 2018 @ 13:48:02

Matthias Noback has posted another article covering domain-driven development practices, this time focusing on testing actual behavior and some of the downsides that can come with it and domain-driven development.

He breaks the article up into three main sections:

  • The downsides of starting with the domain model
  • The downsides of starting with the smallest bricks
  • The downsides of your test suite as the major client of your production code

Each includes a description of the downsides related to the topic and, where it helps, code to illustrate the issue. The post also includes three experiments to try to help prevent some of these downfalls from happening (including not testing constructors and not adding getters).

Tests are not the main use case of an object, they should guide the development process and make sure you write exactly the code that you need. This means not sacrificing the object's encapsulation just to make it testable.
tagged: domaindriven development tutorial testing behavior downsides

Link: https://matthiasnoback.nl/2018/06/testing-actual-behavior/

Matt Sparks:
Building a PHP Framework: Part 5 – Test Driven Development
May 30, 2018 @ 12:55:12

Matt Sparks has posted the latest tutorial in his "Building a PHP framework" series of posts. In this latest article he covers the use of test-driven development during the development of some of the first framework code.

In part 4 we laid the foundation for Analyze. Now it’s time to write the very first lines of code! [...] Essentially, test driven development is a process of writing tests before writing any code, then writing code that passes the tests. [...] If you’re new to TDD, this probably seems pretty weird. Stick with me.

He starts with a brief definition of what test-driven development (TDD) is and what tool he'll be using to create the tests. Next is a simple example of a test that creates a class instance (NumberAdder) and calls an add method on it. This fails because none of this exists yet, hence the "test first" part of TDD. He then goes back and creates the class and method and loads them so the test can use them.

tagged: build framework tutorial series part5 tdd testdriven development

Link: https://developmentmatt.com/building-a-php-framework-part-5-test-driven-development/

Laravel News:
Developing Laravel Packages with Local Composer Dependencies
May 18, 2018 @ 10:10:53

On the Laravel News site they've posted a tutorial sharing some helpful hints for the Laravel users out there about developing package locally without having to release it and wait to pull the latest version back down.

Developing Composer packages locally through a local file symlink speeds up development immensely when you want to create Laravel packages and try them out on a real application. I was reading about a tagged: laravel package local development tutorial composer

Link: https://laravel-news.com/developing-laravel-packages-with-local-composer-dependencies

Benoit Schneider:
The main reasons we use Symfony for web application developments
Apr 16, 2018 @ 11:36:05

On his Medium.com site Benoit Schneider (CTO of Outsourcify) has a post sharing some of the reasons they made the choice to use Symfony for their web development needs.

At Outsourcify we work on projects of varying sizes, from small sites with a few pages to complex business applications. Depending on the case, we recommend different technical solutions (we do a lot of Javascript SPA and Wordpress also), but for the most complex cases, when we have to chose a technology to build large web applications that require several weeks or months of work for several web developers, Symfony is our framework of choice.

He starts with a bit of background on his own experiences with Symfony and why he chose it for his own needs early on. He then shares his thoughts around "why Symfony?" when there are many other major frameworks to choose from. He wraps up the post with a summary of some technical reasons to use the framework including the innovation it brings to the table and the robust ecosystem around it (and related products/tools).

tagged: symfony framework choice development opinion technology

Link: https://medium.com/@outsourcify/the-main-reasons-we-use-symfony-for-web-application-developments-6281d2a56390

Tomas Votruba:
4 Ways to Speedup Your Symfony Development with PackageBuilder
Apr 06, 2018 @ 09:36:07

In a new post to his site Tomas Votruba covers a recent release of the "symplify/package-builder" package for Symfony, detailing each of the updates and including examples of the change in action.

Symplify 4 was released and with it also one package, that contains all the Symfony tweaks that Symplify packages use.

Throwable render? Test services without public violation? Load parameters with glob? We got you covered!

The four new features are:

  • Console-Like -vvv-Aware Renders for Exceptions and Errors
  • Drop Manual public: true for Every Service You Test
  • Autowire Singly-Implemented Interfaces
  • How to Decouple Parameters to multiple files in Safe Way

Each section also comes with some explanation of the change, the code related to it and configuration changes if they're required. You can find out more about the package on its GitHub repository.

tagged: symfony packagebuilder speed development feature update

Link: https://www.tomasvotruba.cz/blog/2018/04/05/4-ways-to-speedup-your-symfony-development-with-packagebuilder/

php[architect]:
The Dev Lead Trenches: Reviewing Code
Mar 26, 2018 @ 11:24:58

On the php[architect] site they've shared an article from their latest edition of the magazine (the March 2018 issue) about reviewing code from the "Dev Lead Trenches" column (by Chris Tankersley).

Code reviews are one of the best ways to help a team ensure they’re writing the best code possible. In all of the jobs where we have done peer-lead code reviews, we have caught more bugs and had better discussions about code than in places or times where we just hammer code through the approval process. I know, I know; we all write beautiful, bug-free code, so why go through the hassle of a code review?

He starts with the idea of relating code reviews back to test-driven development. In TDD the architecture and quality thinking comes up front and with code reviews that same kind of thinking happens with the second (or third) set of eyes as the code progresses. He then lists out a few helpful tools for code reviews including GitHub/GitHub Enterprise's own pull request system and similar features in Gitlab. He ends the post with some suggestions for successful code reviews including "don't punish", "ask questions" and "have clear intentions" (avoid vague questions).

tagged: phparchitect march2018 article codreview development lead

Link: https://www.phparch.com/2018/03/the-dev-lead-trenches-reviewing-code/