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

Master Zend Framework:
Preparing Legacy Applications for PHP 7 with Phan
Sep 08, 2016 @ 12:07:42

The Master Zend Framework site has posted a new tutorial for those making the move in their legacy applications up to the world of PHP 7. In it Matthew Setter shows how to use phan, a static analysis tool, to locate issues that could cause breakage in the upgrade.

Unless you’ve been living under a rock these last 12 - 18 months, you will have heard about PHP 7; the latest version of PHP. Not only is it fast, by some reports it’s up to twice as fast as PHP 5.6, and far less memory hungry.

[...] Unfortunately, your application’s source code may not be 100% compatible with version 7. Upgrading may well leave you with a broken application and a set of unhappy customers. So before you go breaking your site in the interests of speed and being one of the cool kids, find out if your code’s compatible. How? By using a static code analyser, one which gives you all the changes you need to make on your code, so that you can upgrade with confidence.

He then shows how to install the Phan tool via Composer and execute it against your codebase. The result of his commands are a file that contains the issues found during the scan. If there are some "false positives" you'd like to ignore he also shows you how to create a config.php file with these and other values set to make it all more reusable.

tagged: php7 upgrade phan detect static analysis code tutorial

Link: http://www.masterzendframework.com/preparing-for-php7-with-phan/

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/

GetStream.io Blog:
Build Scalable Newsfeeds with PHP 7 and Laravel – in 60 Minutes
Aug 01, 2016 @ 12:56:57

In a recent post to their blog GetStream.io shows you how to build scalable news feeds with Laravel (and their service).

With all the excitement around the release of PHP 7 – here at Stream we have decided to give our own PHP a refresher – from our client, example apps, and Laravel framework integration. The original Stream PHP example application is built upon Laravel 5.0, as well as a branch for use in Laravel 4. We’re happy to say that the Stream-Laravel framework integration is compatible with 5.2 – and if you follow this post, we’ll be building an example application that works with 5.2 using Stream-Laravel.

The tutorial then goes through all the steps and tools you'll need to get a complete application environment set up:

  • Create LEMP Stack Droplet in DigitalOcean
  • Installing and Configuring PHP 7
  • Laravel 5.2 Quickstart Example Application Setup
  • Integrating Stream via Stream-Laravel into Quickstart Example

The end result is a basic social app that allows for basic feed functionality and includes the ability to follow/unfollow certain users.

tagged: newsfeed getstreamio tutorial laravel php7 scalable

Link: http://blog.getstream.io/build-scalable-newsfeeds-with-php-7-and-laravel-in-60-minutes/

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/

Joseph Silber:
The new Closure::fromCallable() in PHP 7.1
Jul 26, 2016 @ 10:20:47

In a new post to his site Joseph Silber looks at a new feature that will be coming with the next release in the PHP 7.x series - PHP 7.1 - the ability to convert a callable type into an actual Closure instance.

With PHP 5.5 going EOL earlier this week and the PHP 7.1 beta expected later this month, now sounds like a good time to look into a neat little feature coming in 7.1: easily converting any callable into a proper Closure using the new Closure::fromCallable() method.

He starts with a quick refresher on what closures/callables are in PHP (or an introduction for those not already familiar) including a simple example with the reject handling on a Laravel collection. He then modifies the example to try to pass in a base PHP function. This doesn't work directly (as it's not technically "callable" how it's expecting) so he wraps the is_float in a closure instead. This is a bit of a hassle and not as reusable so he updates it for PHP 7.1 and uses the Closure::fromCallable handling to make it automatically. He follows this with another example use case: calling a private method with the array of object/method name from inside the class.

tagged: closure callable fromcallable php7 example introduction

Link: https://josephsilber.com/posts/2016/07/13/closure-from-callable-in-php-7-1

Michelangelo van Dam:
Compile PHP 7 on Mac OS X 10.11 "El Capitain"
Jul 19, 2016 @ 09:34:33

In a new post to his site Michelangelo van Dam has posted a guide to compiling PHP 7 on OSX "El Capitan", the latest release of the popular Apple operating system.

Apple has made a numerous changes to the way OS X (10.11) "El Capitain" uses open source elements like PHP and OpenSSL. Compiling PHP from source requires a bit more modifications.

This article is a follow-up on my previous post <a href='http://www.dragonbe.com/2015/12/installing-php-7-with-xdebug-apache-and.html">Installing PHP 7 with XDebug, Apache and MySQL on OS X Yosemite.

He then provides the commands and configuration information you'll need to get things up and running:

  • OpenSSL
  • PHP 7
  • Apache

The end result is a simple PHP 7 installation with plenty of features installed.

tagged: compile php7 mac osx elcapitan openssl apache

Link: http://www.dragonbe.com/2016/07/compile-php-7-on-mac-os-x-1011-el.html

Thijs Feryn:
What are Type Errors in PHP 7?
Jul 15, 2016 @ 09:58:19

In a new post to his site Thijs Feryn has shared an overview of the different types of type errors that can pop up in PHP 7. This includes both a text-based and video based versions depending on your preference.

PHP 7 has a concept called Type Errors. These errors are thrown on a type mismatch when interacting with functions. They can be caught just like exceptions. I created a video that explains the situation. This blog post goes into more detail and has some code examples.

The post gets into the details of the type errors including topics like:

  • new type hints that were introduced
  • how you can manually throw type errors
  • when PHP itself would throw the errors
  • type coercion

There's also a brief section about strict typing and how that changes what errors PHP might throw in your scripts.

tagged: type error php7 introduction overview video tutorial

Link: https://blog.feryn.eu/type-errors-php-7/

Paragon Initiative:
Securing a PHP Application in 2016: The Pocket Guide
Jul 11, 2016 @ 12:45:11

The Paragon Initiative has posted a new tutorial giving you a pocket guide version to securing your PHP application in 2016.

Please set aside most of what you've heard over the years; chances are, most of it just muddies the water. Security is not a product. Security is not a checklist. Security is not an absolute.

Security is a process. Security is an emergent property of a mature mindset in the face of risk.

Perfect security is not possible, but attackers do have budgets. If you raise the cost of attacking a system (your application or the networking infrastructure it depends on) so high that the entities that would be interested in defeating your security are incredibly unlikely to succeed, you'll be incredibly unlikely to be compromised.

The post talks about the "essence of security" and how most prevention methods don't even add much processing overhead or overall development time. He makes four recommendations of things to do in current and future development to help secure your applications:

  • Use PHP 7 in All New Development
  • Use HTTPS Everywhere
  • Use Security Headers
  • Use Trustworthy Reference Material

The post ends with a few other things to think about when building secure applications including raising the "cost" of attacking your system and keeping in mind that your platform may not be the attacker's "end game".

tagged: paragoninitiative secure application pocket guide top4 php7 https headers references

Link: https://paragonie.com/blog/2016/07/securing-php-application-in-2016-pocket-guide

PHP.net:
PHP 7.1.0 Alpha 3 Released
Jul 08, 2016 @ 12:57:39

The PHP development group has officially announced the release of the latest alpha in the PHP 7.1.x series: PHP 7.1.0 Alpha 3. This is a preview release and should not be used for production applications.

The PHP development team announces the immediate availability of PHP 7.1.0 Alpha 3. This release is the last alpha for 7.1.0. All users of PHP are encouraged to test this version carefully, and report any bugs and incompatibilities in the bug tracking system.

This release includes new features including an Iterable type, HTTP/2 server push support, creating closures from callables and more precise float values. You can see the full list of additions and changes in the NEWS and UPGRADING files. If you're interested in trying out this latest alpha, you can get the latest source release from here and the Windows binaries here.

tagged: language release alpha php7 preview development

Link: http://php.net/index.php#id2016-07-07-1