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

Rudi Theunissen:
Efficient data structures for PHP 7
Feb 09, 2016 @ 10:49:37

In this recent article over on Medium.com Rudi Theunissen looks at more efficient data structures for PHP 7 and the introduction of a library that wants to help replace some of the current functionality and dependencies on things like arrays.

PHP has one data structure to rule them all. The array is a complex, flexible, master-of-none, hybrid data structure, combining the behaviour of a list and a linked map. But we use it for everything, because PHP is pragmatic.

[...] The recent release of PHP 7 caused a lot of excitement in the PHP community. We couldn't wait to start using the new features and get a taste of the ~2x performance boost. One of the reasons why it runs that much faster is because the array was redesigned. But it’s still the same structure, “optimised for everything; optimised for nothing” with room for improvement.

He starts with a brief mention of some of the current topics around data structures - the SPL functionality, why fixing them would be difficult and, finally, introducing the library that seeks to supersede them. The remainder of the post goes through the pieces of functionality the library offers and explains how each works including videos and graphs of the performance results:

  • Collection
  • Sequence
  • Vector
  • Deque
  • Stack
  • Queue and PriorityQueue
  • Hashable
  • Map
  • Set

He also answers some of the most common questions he's gotten about the library including the level of testing, documentation for the project and why he structured certain elements and features how he did.

tagged: data structure php7 library ds spl optimized video code

Link: https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd#.xg74fpxwg

Toptal.com:
Data Encoding: A Guide to UTF-8 for PHP and MySQL
Jan 28, 2016 @ 13:22:56

The Toptal.com blog has posted a guide to data encoding in PHP and MySQL looking specifically at the use of UTF-8 and related handling. They talk about some of the updates you'll need to make to configurations, code and the MySQL settings to fully support this character set.

As a MySQL or PHP developer, once you step beyond the comfortable confines of English-only character sets, you quickly find yourself entangled in the wonderfully wacky world of UTF-8.

[...] Indeed, navigating through UTF-8 related data encoding issues can be a frustrating and hair-pulling experience. This post provides a concise cookbook for addressing these issues when working with PHP and MySQL in particular, based on practical experience and lessons learned (and with thanks, in part, to information discovered here and here along the way).

They start with the changes on the PHP side, updating the INI settings to make UTF-8 the default character set and which functions you'll need to update and replace. With those changes out of the way they move to the MySQL side, changing up settings in the my.cnf file and a few other things to consider on the database side (including that the MySQL support for UTF-8 is only a partial character set).

tagged: toptal data encoding mysql utf8 update configuration code

Link: http://www.toptal.com/php/a-utf-8-primer-for-php-and-mysql

Lorna Mitchell:
Insert Data with Phinx
Dec 18, 2015 @ 10:49:07

Lorna Mitchell has a new post to her site with a quick tip for any of the Phinx users out there around a new feature they've added: database seeding.

Database patching is a wicked hard problem, one that's got a bit easier in my world lately as I've been using Phinx on a few projects. [...] One thing I didn't immediately find was how to insert data. Phinx has seed functionality but in this case I needed to put in a lookup table to go along with a data structure change.

She includes a code examples of this new feature, showing how to create a roles table and seed it with a new record with a "name" value of "admin". She also mentions one "gotcha" in the name of the function used to save the data to the new table (saveData versus just save).

tagged: phinx insert data database migration example tutorial

Link: http://www.lornajane.net/posts/2015/insert-data-with-phinx

SitePoint PHP Blog:
Filling out PDF Forms with PDFtk and PHP
Dec 03, 2015 @ 12:35:08

On the SitePoint PHP blog they've posted a tutorial from Reza Lavaryan showing how to fill out PDF forms with PDFtk and a bit of PHP on the side. PDFtk is a toolkit that provides easier handling for PDF files and content.

PDF files are one of the most common ways of sharing documents online. Whether we need to pass our clients’ documents to third-party service providers like banks or insurance companies, or just to send a CV to an employer, using a PDF document is frequently the first option.

PDF files can transfer plain/formatted text, images, hyperlinks, and even fillable forms. In this tutorial, we’re going to see how we can fill out PDF forms using PHP and a great PDF manipulation tool called PDFtk Server.

They walk you through the installation of the pdftk tool on a Homestead (Improved) virtual machine and give an overview of how it works and what makes up a PDF file. He then shows how to use PHP's exec function to make calls to the pdftk command line tool and fill in a form by editing the raw PDF content. To make it even easier he shows how to create a simple wrapper class around this that takes in the data to populate, the PDF to use and spits back out the download of the new PDF. The post ends with a quick example of extracting the current fields from the PDF, getting back more human readable output.

tagged: pdf form pdftk tutorial library populate data

Link: http://www.sitepoint.com/filling-pdf-forms-pdftk-php/

Liip Blog:
Magento 2.0 Release
Nov 19, 2015 @ 09:40:01

On the Liip blog there's a post about the release of Magento 2, the latest and hugely reworked version of the popular eCommerce platform. The post walks you through the installation of this latest update using a pre-configured Vagrant machine.

I’ve downloaded my M2 sample from the official Magento website, there I also found an archive with sample data. For a setup I used a pre-configured Vagrant machine according to the installation guide for Magento server. This installation guide offers two options: easy and advanced. Let’s try the easy way first ;) M2 has an installation wizard, so it is supposed that even a none technically prepared user can install it successfully. And indeed, it looks easy.

He walks through some of the issues he had importing the data during the installation, ultimately, falling back to a command line call to push the large sample data into the platform.

You can find out more about this release and get the latest version over on the Magento website with plenty of information about what's been improved, added and how to get started using this latest version.

tagged: magento2 release install import data ecommerce platform

Link: https://blog.liip.ch/archive/2015/11/18/magento-2-0-release.html

ThePHP.cc:
How to Validate Data
Nov 10, 2015 @ 10:18:52

In this post to thePHP.cc site Sebastian Bergmann looks at validation data, both in the sense of user input and the contents of objects you're application is currently working with.

Validating data seems to be one of the most important tasks of an application. After all, you cannot trust data from external sources. So let us have a look at how to efficiently implement data validation.

He gives an example of a user profile with requirements on the data it should contain. He focuses on the email address property as it's one of the easier options to validate (or is it). He walks through the usual progression from controller injection to setter injection of the value but wonders when the validation should happen to keep the Profile object from becoming invalid. He points out that simply having a validate method perform the checks isn't enough as it may not always be called correctly, leading to potentially invalid objects. Instead he recommends an alternative - using a validator object/tool in the setters of your object instance as the values are set. This prevents the object from getting into an unknown state and provides immediate feedback to the developer when something's wrong.

tagged: data validation object recommendation setter business rules

Link: https://thephp.cc/news/2015/11/how-to-validate-data

Woody Gilk:
Immutable Data Structures in PHP
Sep 23, 2015 @ 11:48:34

Woody Gilk has posted an article to his site looking at immutable data structures in PHP and a library that's come from the research and work he did to implement them in PHP.

As someone who most often works with PHP I often find myself envious of the more advanced data structures that are present in a language like Python. As an experiment, I decided to see if it would be possible to bring some of those basic structures to PHP while also preserving immutability. The result of this experiment is Destrukt.

He starts off talking about immutable data structures and introducing some of the basic concepts and usage around them. He notes that they "cannot be modified by accident" and how, if they do need to be changed, they'd actually be reassigned not updated. He then talks about PHP arrays, how they're normally used in PHP and how their flexibility can lead to potential issues in the code. His library implements more strict versions of the same functionality in the form of dictionaries, orderedlists, unorderedlists and sets. He includes examples of using the library to create these objects and how to get the data back out of them for evaluation.

tagged: immutable data structure introduction destrukt dictionary orderedlist unorderedlist set

Link: http://shadowhand.me/immutable-data-structures-in-php/

Bernhard Schussek:
Value Objects in Symfony Forms
Sep 10, 2015 @ 11:35:20

Bernhard Schussek has posted a tutorial on his Webmozart.io site talking about the use of value objects in Symfony forms. By nature value objects don't allow the use of "setters" to assign/change values but he shows how to use a custom data mapper to work around the problem.

Many times, Symfony developers wonder how to make a form work with value objects. For example, think of a Money object with two fields $amount and $currency. [...] Can you write a form type for this class without adding the methods setAmount() and setCurrency()? In this post, I will show you how.

He starts with a bit of an overview on what value objects are and how the concept of immutability comes into play. He shows examples of potential issues if setters are allowed to change data and what should be done when a value change is actually needed. He then gets into the heart of the matter, integrating the forms handling with simple value objects. He goes through building a simple form and the use of the empty_data option to create a new value object with the form values. This works fine but breaks down if you need to update an object. Instead he creates a custom data mapper that sets up two methods, mapDataToForms and mapFormsToData, that allow for both interactions to work correctly.

tagged: value object symfony form tutorial custom data mapper emptydata

Link: https://webmozart.io/blog/2015/09/09/value-objects-in-symfony-forms/

Ignace Nyamagana Butera:
Q&A: Enforcing enclosure with LeagueCsv
Sep 04, 2015 @ 11:19:44

Ignace Nyamagana Butera has a post has a post to his site showing how to use the LeagueCsv library for encapsulation in CSV output.

It is common knowledge that PHP’s fputcsv function does not allow enforcing the enclosure on every field. Using League CSV and PHP stream filter features let me show you how to do so step by step.

He walks you through the process of getting the library installed and using it (seven easy steps) to correctly contain the CSV values according to its contents:

  • Install league csv
  • Choose a sequence to enforce the presence of the enclosure character
  • Set up you CSV
  • Enforce the sequence on every CSV field
  • Create a stream filter
  • Attach the stream filter to the Writer object

Each step includes the code you'll need to make it work and a final result is shown at the end of the post. He does offer a few extra tips at the end of the post around some extra validation he added and where you can register the stream filter.

tagged: leaguecsv csv data output encapsulation stream filter

Link: http://nyamsprod.com/blog/2015/qa-enforcing-enclosure-with-leaguecsv/

Larry Garfield:
Just how insular is the PHP community?
Aug 25, 2015 @ 12:20:37

In this post to his site Larry Garfield takes a look at how insular the PHP community is and, instead of just expressing personal opinions on the subject, looks at data around some of the "same old faces" comments recently pointed at the PHP community.

Periodically, there is a complaint that PHP conferences are just "the same old faces". That the PHP community is insular and is just a good ol' boys club, elitist, and so forth. It's not the first community I've been part of that has had such accusations made against it, so rather than engage in such debates I figured, let's do what any good scientist would do: Look at the data!

He starts with a look at the Joind.in conference feedback site and the data it has to offer. This is what he's basing is research on, pulling the information from the site's JSON API to work through it locally. While the detailed information is attached on another page he does share a summary of his findings. Interestingly enough, just a bit over half of the speakers at these events were first-time speakers. His results show that there's an average of 13.1% of new speakers at each event too.

tagged: insular community conference speaker joindin data results

Link: http://www.garfieldtech.com/blog/php-conference-data