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

TutsPlus.com:
What Are the WordPress PHP Coding Standards?
May 23, 2018 @ 12:51:35

On the TutsPlus.com site they've posted a tutorial sharing some of the current WordPress coding standards when it comes to both the structure and syntax of the code written in WordPress (and suggested for plugins as well).

You can find the full WordPress PHP coding standards in the tagged: wordpress coding standard tutorial example

Link: https://webdesign.tutsplus.com/tutorials/php-coding-standards--cms-31203

SitePoint PHP Blog:
How to Fix Magento Login Issues with Cookies and Sessions
May 21, 2018 @ 11:30:01

On the SitePoint PHP blog there's a new tutorial posted showing how to fix Magento login issue with cookies and sessions. This issue can cause a redirect loop but can be fixed.

In this article are looking at how Magento cookies can create issues with the login functionality of both the customer-facing front-end and admin back-end, the reason it occurs and how it should be resolved.

This is also known as the looping issue, as the screen redirects itself to the same screen, even though the username and password is correct.

The post starts with some basic definitions of "cookie" and "session" and gets into more detail on how Magento stores sessions and the places it can store them. The tutorial then covers each of the cookies used and three reasons the login issues might be happening:

  • Cookie domain does not match server domain
  • Multiple subdomains used and Magento’s cookie configuration is incorrect
  • Double front-end cookies causing intermittent login issues

For each several solutions are included with any code or SQL changes that need to happen to correct it.

tagged: magento tutorial fix login issue cookie session

Link: https://www.sitepoint.com/fix-magento-login-issues-cookies-sessions/

Tomas Vortuba:
Is Your Code Readable By Humans? Cognitive Complexity Tells You
May 21, 2018 @ 10:55:07

In his latest post Tomas Votruba shares some of his thoughts around the importance of code readability and the idea of "cognitive complexity".

Cyclomatic complexity is a static analysis measure of how difficult is code to test. Cognitive complexity tells us, how difficult code is to understand by a reader.

Today, we'll see why is the later better and how to check it in your code with a Sniff.

He references this post and this PDF as sources for more information about cognitive complexity but opts for code examples to explain some of the basic concepts. He then gets into the automation of these kinds of checks, using a custom code sniff to check the complexity of the code. He walks through the installation process of the CognitiveComplexitySniff and shares some example results from its evaluation.

tagged: code readability human cognitive complexity example codesniffer tutorial

Link: https://www.tomasvotruba.cz/blog/2018/05/21/is-your-code-readable-by-humans-cognitive-complexity-tells-you/

Freek van Der Herten:
When empty is not empty
May 21, 2018 @ 09:38:08

As PHP developers, dealing with the "helpful" automatic type shifting the language performs can sometimes be challenging. It can lead to some interesting situations like the one Freek van Der Herten has posted about where something that seems "empty" actually isn't.

Recently when I was working on a project I got some strange results when using the empty function. That's really odd [that the result was a string and "empty" when a value was set]. How can a variable hold a string and be empty at the same time?

He includes a few other tests on the same object and firstName property using other "empty" checks with isset and is_null. Those behaved as expected so he started to look more into the class the object is based on. In the class values/properties are returned via magic methods, not direct functions. In the case of empty, this fetching isn't interpreted prior to the check and the result appears "empty". To fix the issue, he recommends implementing an __isset magic method that will then get called to ensure the value is actually set before fetching it.

tagged: language isset empty property tutorial

Link: https://murze.be/when-empty-is-not-empty

Zend Framework Blog:
Zend Framework/Homestead Integration
May 18, 2018 @ 12:48:26

On the Zend Framework blog, project lead Matthew Weier O'Phinney has posted a tutorial showing you how to set up a Homestead instance for Zend Framework thanks to a few helpful submissions from the ZF project.

Last year, we tagged: zendframework homestead integration tutorial laravel apigility zendexpressive

Link: https://framework.zend.com/blog/2018-05-16-homestead.html

Tomas Vortuba:
How to Test Private Services in Symfony
May 18, 2018 @ 11:21:39

Tomas Vortuba has a tutorial posted to his site showing you how to test private services in Symfony in unit tests for pre-4.1 Symfony installations (it has been resolved via simpler testing methods in Symfony 4.1 with the FrameworkBundle).

2 versions of Symfony are affected by this dissonance between services and tests. Do you use Symfony 3.4 or 4.0? Do you want to test your services, but struggle to get them in a clean way?

Today we look at possible solutions.

He starts with an example of the error you'd face if you tried to pull a service directly from the container that was marked as private. While you can specifically make it public in the yaml configuration, this potentially means doing that for all of the services you need to test. While this might work for smaller projects, it's unmaintainable for larger ones. He then shares some other options that could help resolve the issue including the one he ended up on: a compiler pass. He gets into a bit of detail on the changes this would require and where the "magic" is that lets it work.

tagged: test unittest private service symfony tutorial compiler pass

Link: https://www.tomasvotruba.cz/blog/2018/05/17/how-to-test-private-services-in-symfony/

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

Matt Sparks:
Building a PHP Framework Series (Parts 1-4)
May 16, 2018 @ 12:50:42

On this site Matt Sparks has posted the first few parts of a series covering the creation of a custom framework. Why? Well, as he explains in part one of the series:

So with all of that being said, it begs the question: why on Earth would you want to do this?

The extremely short answer: I want to. The less short answer: A PHP framework encompasses many of the areas I want to learn more about.

The first four posts of the series are already on his site (with more to come):

Matt does a great job of laying out some of the fundamentals behind frameworks including structure, design patterns, and commonalities between frameworks. You can follow along with his progress on the project on the AnalyzePHP GitHub repositories.

tagged: build framework tutorial series part1 part2 part3 part4

Link: https://developmentmatt.com/building-a-php-framework-part-4-the-foundation/

Laravel News:
Introducing View Components in Laravel, an alternative to View Composers
May 16, 2018 @ 10:55:56

On the Laravel News site there's a new post covering a refactoring of view handling that's possible with recent versions of the framework: using view components instead of view composers..

In software development, one of the “best practices” is to create reusable code that can be implemented in different parts of your application if needed. [...] View composers allow you to move the logic outside your controller and pass the data to the specified set of views. [Using view components instead of composers lets you] reuse complex components using dynamic data on any view within your application.

To help illustrate the difference they set up a scenario of a blog with a "highlights" sidebar based on data from an API response. With view composers you could extract this logic out of the controllers and add it more automatically to the view itself. They point out that this can work for a majority of the situations there's another method that is even more flexible: a reusable component implemented directly on the view. He provides the complete code showing an examples of this components, including a custom Blade directive.

tagged: laravel tutorial view composer component refactor

Link: https://laravel-news.com/introducing-view-components-on-laravel-an-alternative-to-view-composers

Joe Ferguson:
Getting Lucky With Crystal in Homestead
May 16, 2018 @ 09:12:27

Laravel users are no doubt familiar with the Homestead VM project that makes it quick and easy to get new sites up and running. In this new post to his site, project maintainer Joe Ferguson covers some changes made to run something besides a PHP framework: a Crystal project.

A few days ago a random internet stranger (Rid) showed up in the Larachat Slack #homestead-dev room. This is about the best real time chat support for Homestead. Rid proceeds to ask about building something like Homestead for the framework he was working on called Lucky for the [Crystal programming language](https://crystal-lang.org/). After we chatted about Vagrant and Docker I mentioned that it wouldn’t be too difficult to get supported in Homestead. Rid shared some helpful URLs and I was off to the races.

Joe mentions that the next Homestead box will come configured to support this out of the box but also provides instructions if you'd like to set it up before that. The Cyrstal language is inspired by Ruby and is designed to be as "fast as C".

tagged: crystal laravel homestead language framework lucky tutorial

Link: https://www.joeferguson.me/getting-lucky-with-crystal-in-homestead/