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

SitePoint PHP Blog:
PHPBot – Can a PHP Bot Help You Look up Documentation Faster?
Aug 16, 2017 @ 10:31:39

On the SitePoint PHP blog there's a new tutorial posted from editor Bruno Skvorc looking at PHPBot, a chatbot tool that might help you look up PHP documentation questions a bit more easily (and quickly).

I came across PHPBot the other day (not to be confused with Botman or Fondbot) – a “chatbot” which helps you look up PHP manual entries and generates example code for them.

If you follow me on Twitter, you know I don’t believe in chatbots being chatbots – as someone who’s built some for both commercial purposes and personal ones, and as someone who was around in the age of IRC auto-responding scripts, I see chatbots as a little more than a marketing fad designed to impress today’s Snapchat generation. However, every now and then one will appear that’s actually useful. Could this be the one? Let’s take a look.

He starts off with some of the basic concepts behind the bot and examples of some of the output from documentation requests. He goes on to talk about the actual usefulness of the bot and provides some instances where it is still lacking in functionality. He also looks at several other subjects including Knowledgebase and Bugs, Autocompletion / Suggestion and Copy / Paste Friendliness.

tagged: phpbot documentation chatbot review feature opinion useful

Link: https://www.sitepoint.com/phpbot-can-php-bot-help-look-documentation-faster/

SitePoint PHP Blog:
What Are the New Features in Laravel 5.5?
Aug 14, 2017 @ 11:22:03

On the SitePoint PHP blog there's a recent article posted by Christopher Vundi looking at the new features coming in Laravel 5.5, the next major release of the popular PHP framework.

Laravel 5.5 will require PHP 7.0+. For the features this modern PHP version brings, please see our recap.

Laravel 5.5 will also be the next LTS (Long Term Support) release. This means bugfixes for two years and three years of security updates. That was also the case with Laravel 5.1, but its two-year window of bug fixes is coming to an end this year. Without further ado, let’s see what this new version has to offer.

Instead of just describing the new features, the article opts to walk you through the installation of v5.5 and showing examples of each. Topics covered include:

  • Rendering Mailables to the Browser
  • Exception Helper Functions
  • Introducing the migrate:fresh Command
  • Automatic Package Discovery
  • Whoops is Back!
  • Custom Exception Report Method
  • Validation Data Return
  • Custom Blade::if() Directives
  • Autoregistering of New Artisan Commands in the Kernel

...among many others. There's a long list of new features coming in this release and the tutorial covers each nicely and provides the code examples it would take to make it all work.

tagged: laravel new feature v55 framework example code

Link: https://www.sitepoint.com/new-features-laravel-5-5/

Scotch.io:
What's New in Laravel 5.5
Jul 07, 2017 @ 13:07:47

The Scotch.io site has posted a new article sharing some of the new features and changes that are coming with Laravel 5.5, the next major release of the framework.

At the time of this writing, Laravel 5.5 is not released yet. It is slated, as the next major release, for release in July 2017. To play around with new features and changes, you need to grab the dev release of Laravel using this Laravel Installer command: laravel new project --dev

The article starts by pointing out that this version will require at least PHP 7.0, a supported and much more performant version of the language. It then covers the changes in this version including:

  • the reintroduction of the "Whoops" library for debugging/error handling
  • a change to vendor:publish to get a new provider prompt
  • email themes
  • automatic package discovery
  • error page design improvements
  • streamlined request validation
  • exception helper functions
  • model factory generators

Each of these items comes with screenshots or code examples showing the new feature at work. It also ends with a few miscellaneous updates mentioning changes in the CSRF handling and the return of a JSON stack trace for API calls.

tagged: laravel version feature update changes php7 v55 framework

Link: https://scotch.io/tutorials/whats-new-in-laravel-55

Laravel News:
Laravel 5.5 Pivot Casting
Jul 06, 2017 @ 09:15:36

On the Laravel News site there's a new post about a feature in the v5.5 release of the popular framework: pivot casting.

A new addition to Laravel 5.5 will add support for pivot table casts when inserting & updating data on an intermediate table model.

Currently, the $casts you set on a traditional model will work in both directions; any model that extends the EloquentModel class will look for a $casts property and convert the specified attributes to a data type when reading and writing.

[...] Now with Laravel 5.5, the $casts property on the EloquentModel and EloquentRelationsPivot classes will behave the same. Laravel will “respect” your casts on both, whether you’re reading, inserting or updating data.

tagged: laravel pivot casting feature insert update

Link: https://laravel-news.com/laravel-5-5-pivot-casting

TutsPlus.com:
Building Your Startup: Approaching Major Feature Enhancements
May 30, 2017 @ 11:57:50

The TutsPlus.com site has continued their series covering the use of PHP and the Yii2 framework to build an application from the ground up (a "startup"). In this latest post the author covers some major feature enhancements, how to handle them and the code to add in the one he chose - an "Activity Planning" feature.

These days I'm most often working to add small incremental improvements to Meeting Planner. The basics work pretty well, and I'm trying to gradually improve the application based on my vision and people's feedback. Sometimes, my vision is for a bigger change, and that can be harder now that the codebase has grown so much.

In today's tutorial, I'm going to talk about ways to think about making bigger changes to an existing codebase. Specifically, I'll walk you through the impacts of adding the ability for meeting participants to collaboratively brainstorm and decide on activities, i.e. what we should do when we meet up.

His intent is to expand the scheduling support for the product to add the idea of "activities" to the invitations. These are suggestions of things to do during the time specified (if there's not only one option). He starts off by scoping out the changes that will be required including both the customer and code facing impacts. The tutorial then goes through some of the highlights of the code added to include this new feature. Finally he loops back around and reflects on the changes made during this latest addition and how his expectations measured up against the reality of the work done.

tagged: startup build tutorial series yii2 major feature enhancement

Link: https://code.tutsplus.com/tutorials/building-your-startup-approaching-major-feature-enhancements--cms-27850

Stitcher.io:
PHP Generics and why we need them
May 23, 2017 @ 09:48:56

On the Stitcher.io blog there's a post that's advocating the addition of a feature to the core PHP language that several others have: generics. The basic idea behind generics is to provide functionality that allows the definition of entity types that can be reused as a default (like a "collection" generic that could be used instead of a base collection class).

In today's blog post we'll explore some common problems with arrays in PHP. All the problems and issues listed could be solved with a pending RFC which adds generics to PHP. We won't explore in too much detail what generics are. But at the end of this read, you should have a good idea as to why they are useful, and why we really want them in PHP. So without further ado, let's dive into the subject.

They start off with a common use case in PHP: a collection of blog posts and getting information from them. There's no guarantee that the contents of the set are always post objects leading to specific checks to ensure data quality before use. The post then uses a common example from PHP, the creation of a collection class to handle a set of objects and then showing how (with pseudo-code as generics aren't in the language) how that same functionality might look defined as a generic collection instead.

tagged: generics language feature example rfc collection

Link: https://www.stitcher.io/blog/php-generics-and-why-we-need-them

Tighten.co:
The Magic of Laravel Macros
Apr 13, 2017 @ 11:18:50

On the Tighten.co blog there's a recent post showing off some of the magic of Laravel macros and how they can make extending the basic framework functionality simpler.

Ever wanted a piece of functionality in a part of Laravel that doesn’t exist? Let me introduce you to Laravel macros. Macros allow you to add on custom functionality to internal Laravel components.

He gives an example of adding a simple "introduce" macro on the Request facade and how to put it to use. He refactors this into something more useful: returning a true/false result when checking the TLD on the current domain. He includes the code to set up the macro in the AppServiceProvider and the addition of an enhancement that adds a "where" clause to a model query when the TLD matches. He wraps up the post giving some guidance on where they should be defined and what components in the Laravel framework are "macroable".

tagged: laravel macro feature provider functionality extend tutorial

Link: https://blog.tighten.co/the-magic-of-laravel-macros

PhpStorm Blog:
Working With PHPUnit and PhpStorm
Mar 23, 2017 @ 11:50:12

On the PhpStorm blog (from JetBrains) Gary Hockin reflects on a post from Adam Wathan with tips for combining PHPUnit and PhpStorm for more effective debugging.

Community stalwart and Laravel aficionado Adam Wathan blogged on his PHPUnit workflow in Sublime text.

Gary then goes through the points in Adam's post and shows how they can (mostly) be accomplished directly in PhpStorm:

  • Generating unit test boilerplate for a class
  • Using "snippets" to create shortcuts for reusable code
  • Running the tests in just one file directly from the IDE

Each section comes with a brief description and animated screen grabs showing the flow of the setup and use for each.

tagged: phpstorm debugging unittest feature generation snippets singlefile tutorial

Link: https://blog.jetbrains.com/phpstorm/2017/01/working-with-phpunit-and-phpstorm/

Sameer Borate:
New features in PHP 7.1
Feb 13, 2017 @ 10:57:45

The PHP 7.1.x releases are some of the latest versions of the language. There's plenty of new features that came along with this new release. In this new post to his CodeDiesel blog Sameer Borate looks at some of these new features (including code snippets to illustrate).

The PHP development team announced PHP 7.1.0 on 01 Dec 2016. This release is the first point release in the 7.x series. There are a few features – like the void return type – which have been introduced. Below are a few new selected features in PHP 7.1.

In the post he covers:

  • void functions (return type)
  • nullable types
  • symmetric array destructuring
  • class constant visibility

For each, code samples are provided and some of the benefits (and limitations) that come along with them.

tagged: feature php71 void nullable array class constant summary

Link: http://www.codediesel.com/php/new-features-in-php-7-1/

SitePoint PHP Blog:
How to Make Modern PHP More Modern? With Preprocessing!
Feb 03, 2017 @ 11:20:47

The SitePoint PHP blog has posted another tutorial from author Christopher Pitt sharing another one of his "interesting things" you can do with PHP. In this latest article Christopher returns to the idea of "macros" to help with some pre-processing in PHP applications and, ultimately, creating a new language feature without some of the usual overhead.

Let’s have a bit of fun. A while ago, I experimented with PHP macros, adding Python range syntax. Then, the talented SaraMG mentioned an RFC, and LordKabelo suggested instead adding C#-style getters and setters to PHP.

Aware of how painfully slow it can be for an outsider to suggest and implement a new language feature, I took to my editor…

He starts with a brief refresher on macros to do some pre-processing on PHP scripts and allow you to make custom language features that then get interpreted into valid PHP (often with some interesting eval tricks involved). He starts by building a "base" to add in the C# style getters and setters in a special format inside of a class. He includes the macro definitions to set this up and the result once it is passed through the "yay" precompiler. To get around having to run that precompiler every time manually, he creates a custom autoloader to do the job dynamically. He then takes this logic and packages it up so it can be easily installed as a Composer dependency. With this structure in place, he moves on to the creation of a new language feature - the actual functionality for the getter/setters. He ends the post with a screen capture showing the language feature in use and some of the interesting things you can do with it.

tagged: precompile macro tutorial language feature getter setter

Link: https://www.sitepoint.com/how-to-make-modern-php-more-modern-with-preprocessing/