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

Alex Bowers:
Writing a Hello World PHP 7 Extension
Aug 25, 2016 @ 12:25:47

In a recent post to his site Alex Bowers shows you the steps involved in creating a "Hello World" PHP 7 extension with some basic output functionality - basically just echoing out a message.

He jumps right into the code and shows you how to:

  • set up the directory and initial files for the extension
  • write the test case first (a simple PHP file checking if it's loaded and can be used)
  • updating the config.m4 to allow for enabling the extension
  • the code for src/hello.h to define the function

The final piece is the code in the src/hello.c - the C code to define some structure for the PHP interpreter to understand and be able to execute the PHP_FUNCTION(hello_world). Finally he shows how to make the extension to install it, add it to your php.ini file as a shared module and re-run the test.

tagged: helloworld extension tutorial example simple php7

Link: https://zando.io/writing-a-hello-world-php-7-extension/

SitePoint PHP Blog:
Up and Running with the Fastest PHP Framework on PHP7 in 5 Mins
Aug 24, 2016 @ 11:22:46

On the SitePoint PHP blog editor Bruno Skvorc has posted a tutorial helping you get up and running with PHP 7 and Phalcon in five minutes on a Homestead Improved virtual machine.

You may remember our past infatuation with Phalcon, the fastest PHP framework.

In this post, we’ll go through the process of getting it up and running in 5 minutes on one of our <a href="http://www.sitepoint.com/quick-tip-get-homestead-vagrant-vm-running/>Homestead Improved instances. If you’re not interested in why or what Phalcon is, just skip ahead to “Setting it up”.

He starts with a brief recap of what the Phalcon framework is (including Zephir), some history behind it and the latest advancement around the framework: LTS support for v3.0. The tutorial then gets into the setup and configuration of the VM along with PHP 7 and the latest stable version of Phalcon. He then uses the sample application provided by Phalcon and getting it boostrapped and running.

tagged: phalcon php7 tutorial demo homesteadimproved vm setup configure extension

Link: https://www.sitepoint.com/up-and-running-with-the-fastest-php-framework-on-php7-in-5-mins/

SitePoint PHP Blog:
Can We Have Static Types in PHP without PHP 7 or HHVM?
Jul 26, 2016 @ 11:34:57

On the SitePoint PHP blog Younes Rafie asks the question "Can we have static types in PHP without PHP 7 or HHVM?" One of the main features introduced by both of these versions (or platforms) is the ability to type things strictly and enforce more correct data handling. Previously PHP has been a "lazy typing" language and would regularly shift the type of a variable depending on the immediate need. Obviously, this can lead to unpredictable behavior.

Now that PHP 7 has been out for a while with interesting features like error handling, null coalescing operator, scalar type declarations, etc., we often hear the people still stuck with PHP 5 saying it has a weak typing system, and that things quickly become unpredictable.

Even though this is partially true, PHP allows you to keep control of your application when you know what you’re doing.

They show how, through a series of examples, to add a bit of additional validation with exceptions to ensure the input is the correct type. However this can be a bit more time consuming and difficult to remember so the team at Box put together the augmented types extension that brings some of the static typing to PHP 5.x. They help you get it installed and working in your PHP installation and include an example of it in use with DocBlock-based type hints. The extension provides handling for the basic types as well as arrays, multiple arguments, default values and return types.

tagged: static types php7 hhvm extension augmented types tutorial

Link: https://www.sitepoint.com/can-we-have-static-types-in-php-without-php-7-or-hhvm/

SitePoint PHP Blog:
Localizing Dates, Currency, and Numbers with Php-Intl
May 23, 2016 @ 12:52:32

On the SitePoint PHP blog Younes Rafie has continued his series about the PHP "Intl" extension for use in internationalizing an application. in this second part of the series he moves away from just strings and looks at using it for currencies and numbers.

The first part of this series was an introduction of the PHP Intl extension and of how to localize your application’s messages. In this part, we’re going to learn about localizing numbers, dates, calendars, and similar complex data.

The post is broken down into a few different sections, each with their own examples:

  • Localizing Decimals
  • Localizing Currencies
  • Timezones
  • Calendars

The "Intl" extension makes these operations relatively simple with plenty of built-in objects and methods to help with the translations between the formats. You can find out more about this extension in the PHP manual.

tagged: date currency localization number tutorial intl extension series part2

Link: https://www.sitepoint.com/localizing-dates-currency-and-numbers-with-php-intl/

SitePoint PHP Blog:
Localization Demystified: Php-Intl for Everyone
May 17, 2016 @ 09:44:39

The SitePoint PHP blog has posted a tutorial from Younes Rafie that wants to help demystify internationalization functionality in your PHP application...with the help from a handy extension, the intl extension.

Most applications perform locale aware operations like working with texts, dates, timezones, etc. The PHP Intl extension provides a good API for accessing the widely known ICU library’s functions.

He walks you through the installation of the extension if you don't have it already for both PHP 5 and PHP 7 (the second requires adding a custom apt-get repository). With that all installed and configured he starts in on the code to output a simple message with formatting using the MessageFormat functionality. His first example is in English but he also shows the difference between that and Arabic and Bengali and they're related output. He looks at a few other topics including pluralization, "choices" (different messages for different values) and more complex cases. He ends the post briefly looking at message parsing - extracting a value according to the provided format.

tagged: localization internationalization i18n messageformat intl extension tutorial

Link: https://www.sitepoint.com/localization-demystified-understanding-php-intl/

Marcel Pociot:
Laravel TestTools (Chrome Extension)
Mar 22, 2016 @ 10:48:10

Marcel Pociot has a new post on his site introducing a new tool he's created allowing for the easier creation of tests for your Laravel application: the TestTools Chrome extension.

Testing a Laravel application really is an easy task - the "Integrated" package from Jeffrey Way, that later got merged into the core framework is fantastic and helps you with the otherwise cumbersome task of testing and interacting with your application. But still - are you actually using tests?

A lot of times people really love the idea of tests, but simply don't get their asses up to start using them in their own projects. That's why I created a chrome extension that hopefully saves you some time when you need to test your app

He also includes an animation or two of the Chrome extension in action, showing you what kind of results you can expect. He does point out that there's some limitations of the tool including the fact that you can't really test a single-page application with it as it relies on the normal browser interaction points, not Javascript events.

tagged: laravel testing unittest chrome extension browser

Link: http://marcelpociot.com/blog/2016-03-21-laravel-testtools

Lorna Mitchell:
PHP 7.0 (and 5.6) on Ubuntu
Feb 11, 2016 @ 10:52:59

In this new post to her site Lorna Mitchell show you how to get both PHP 7 and PHP 5.6 installed on a Ubuntu-based system with the help of a custom PPA (Personal Package Archive).

PHP 7 is released but for those of us who don't usually compile our own PHP, it can be a long wait for our preferred distro to release the packages we want. For Ubuntu, I'm using a PPA which allows both PHP 5.6 and PHP 7.0 to be installed, including things like extensions, at the same time. It was very easy to set up (I'm running Ubuntu 15.10 but this process should also work on older versions back to at least 14.04 which is the previous LTS) so here's a quick walkthrough of what I did.

She then shows you how to:

  • Add the PPA to your system (this one)
  • Install the new versions as expected with apt-get
  • Configuring and switching between versions as needed

She ends the post talking about extensions and the issues that could come up when compiling them against each of the versions. This includes installation instructions so you can easily enable and disable the extensions much like the "sites available" some Apache installations use.

tagged: php7 php56 ubuntu ppa package install custom extension tutorial

Link: http://www.lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu

SitePoint PHP Blog:
Can PHP Be Even Faster? Light-Speed with the Blink Framework
Jan 18, 2016 @ 09:20:27

The SitePoint PHP blog has a tutorial posted that looks at a framework that could "make PHP go even faster", the Blink framework.

Blink was built to improve high performance applications that consume a lot of server resources, and it uses the Swoole PHP extension to achieve this goal. As an example, we will build a Blink powered notejam for our demo.

First the tutorial walks you through the installation of the Swoole extension (they choose from PEAR but you can also install from GitHub). Next up they install the Blink framework with a new project and fire up the built-in server to ensure it's working correctly. With that up and running they show how to configure the framework/server and get into building the sample "notejam" application. They make use of Twig for templating the frontend and several Illuminate packages for the database, console and filesystem functionality.

The remainder of the post walks through the actual code for the application:

  • creating and using the "notes" table
  • working with routing
  • creating templates
  • working with user management

Finally, with this system in place they show how to have a user verify themselves and add a new note to their list.

tagged: blink framework fast swoole extension tutorial note application

Link: http://www.sitepoint.com/can-php-be-even-faster-light-speed-with-the-blink-framework/

Antonios Pavlakis:
Having a go at creating a Behat 3 extension
Jan 15, 2016 @ 12:42:10

In this post to his site Antonios Pavlakis "has a go" at creating an extension for the Behat (v3) testing tool. Behat is a testing tool written in PHP that helps with behavior-driven testing as opposed to unit testing with a tool like PHPUnit.

Ever since I got accepted to do a tutorial on Test legacy apps with Behat at the PHPNW15 conference, I’ve been meaning to look into creating custom extensions for Behat. I didn’t have enough time to research into this while preparing for the tutorial, so left it in my todo list in Trello.

During the PHPNW15 long weekend (Friday - Monday), at some point over lunch I was at the table where Matt Brunt (@themattbrunt) and Ciaran McNulty (@ciaranmcnulty) were having a conversation about this and Ciaran said (paraphrasing) “In order to be able to write an extension, you really need to understand how Behat works.”

So a few months later, sleeves up and I went into my vendor/bin/behat and started looking (and poking) around.

After looking in to two current extensions he started to get a feel for what was needed and the pieces that made up an extension. He then gets into detail on each of these pieces and shares some code/configuration he used to create the extension.

tagged: behat testing extension tutorial example behat3

Link: http://pavlakis.info/php/23-having-a-go-at-creating-a-behat-3-extension

Evert Pot:
Strict typing in PHP 7 - poll results
Jan 15, 2016 @ 11:19:54

Evert Pot has shared the results of a poll he recently set up on Twitter asking PHP developers if they planned to make use of the strict typing functionality in PHP 7 in their applications. Unsurprisingly, the majority voted that they will with a more undecided audience coming in second.

Type hinting comes in two flavors: strict and non-strict. This is the result of a long battle between two camps, a strict and non-strict camp, which in the end was resolved by this compromise.

Now by default PHP acts in non-strict mode, and if you'd like to opt-in to strict-mode, you'll need to start every PHP file with this statement. [...] So I was curious about everyone and whether you will be using strict mode or not. Results are in.

According to those that voted 46% were completely in favor of using the declare statement to enable strict typing in their PHP 7 code by default. The next group, the "undecided" were at 26% with "no way" and "what is that?" coming in farther down the list. He also mentions a package that's in the works from Justin Martin that would automatically add the declare statement to your code in the desired location(s). Additionally there's an extension in development from Joe Watkins that will do the same thing but making it a bit more automatic.

tagged: php7 strict type declare poll results usage composer package extension

Link: https://evertpot.com/strict-types-pollresults/