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

Julien Pauli:
PHP closures
Jul 10, 2015 @ 10:54:29

Julien Pauli has posted a look at PHP's closures and how they're actually handled internal to the language.

Back in 2009, when PHP 5.3 got released, a new feature (among many others) were introduced : anonymous functions (also called lambdas or closures). The feature was very expected, as closures have proved their utility through several other languages, particularly javascript that web developers master. [...] Let's see together how Closures have been added to PHP, as usual by turning to the truth : the PHP source code.

He starts at the beginning (a good place to start) and talks about the work that needed to be done on the internals before closures could even be introduced. He walks through the changes made to object handling to make them "callable" and the addition of the "zend_closure" object type. He then gets to the part where "the magic happens" and shows how the userland closure is translated and executed. He ends the post with a look at two other topics: scoping with "$this" and the special handling that was needed for reflection and direct calls to "__invoke".

tagged: closure language functionality object callable scope reflection invoke

Link: http://jpauli.github.io/2015/07/08/php-closures.html

Community News:
Packagist.org Gets a Makeover
Jun 16, 2015 @ 11:55:42

If you're a Composer user by now you've noticed a major overhaul that's happened to the Packagist.org website in the last few days. They've made a major improvement to how the site looks and have added some fun new functionality to help make finding packages easier.

According to the Laravel News site, updates include a change in the recommended install method, the addition of more GitHub metadata and the inclusion of the project's README file. The site will also allow you to sort (ascending and descending) by the number of stars the repository has as well as the number of downloads.

The site still includes all of the information it dod before too including version listings, details about what the package requires, license information and links to more information and the actual repository. Check out the new look and see what you think. Packagist is also an Open Source project so if you find an issue, be sure to either report it to the project or get in, fix it yourself and make the pull request to submit it.

tagged: packagist composer makeover functionality update website

Link: http://packagist.org

NetTuts.com:
Programming With Yii2: Sluggable Behavior
May 13, 2015 @ 12:53:33

NetTuts.com has continued their series looking at programming with the Yii2 framework in this latest part of the series covering the "sluggable" behavior the framework includes.

In this Programming With Yii2 series, I'm guiding readers in use of the newly upgraded Yii2 Framework for PHP. In this tutorial, I'm going to show you how to modify Yii's default view URL routes for model objects to be more user friendly and search engine friendly. Yii provides built-in support for this via its sluggable behaviors. For these examples, we'll continue to imagine we're building a framework for posting simple status updates, e.g. our own mini-Twitter.

They start the tutorial off by defining what a "slug" is for those that may not have used them before. From there they show you how to add in the behavior to the current version of their sample application, adding a new "slug" column to their status table. They then update the status model to reflect the changes and test it out with the insert of a new update. They also show how to implement the slug handling in your routing and add the functionality to the controller to handle the different request. They finish off the post with a mention of managing permanence and uniqueness to prevent overlaps.

tagged: series yii2 framework sluggable slug functionality tutorial

Link: http://code.tutsplus.com/tutorials/programming-with-yii2-sluggable-behavior--cms-23222

SitePoint PHP Blog:
Using Traits in Doctrine Entities
Dec 09, 2014 @ 12:16:56

On the SitePoint PHP blog there's a recent post showing you how to use traits with Doctrine entities. PHP's traits allow for the inclusion of functionality into a class without having to extend another class or create an object to use it.

Since PHP 5.4.0, PHP supports a pretty way to reuse code called “Traits” – a set of methods that you can include within another class in order not to repeat yourself. You can read more about traits in previously published SitePoint posts: here, here and here. Today, I am going to show you how they can be used with Doctrine ORM in a Symfony Environment.

He shows how to create two basic Doctrine entities, in this case representing "Article" and "Comment" instances. He then creates the trait, a "TimestampableTrait" class that abstracts out the setting/updating of the create and updated date on the Doctrine record. He refactors the entities to use the trait and shows the results of the "schema create" command.

tagged: traits doctrine entity tutorial introduction functionality

Link: http://www.sitepoint.com/using-traits-doctrine-entities/

Derick Rethans:
Code Coverage: The Present
Dec 02, 2014 @ 11:54:01

Derick Rethans has posted the first in a series focusing on the Xdebug tool and the code coverage functionality it can provide via PHPUnit's testing. In this first post he catches the reader up on the current state of things and what all the Xdebug tool can do.

Since ages Xdebug has provided code coverage support for PHPUnit, a way to show which lines are covered by your test cases. But I never really wrote about how it works. A recently filed bug prompted me to write this post, as well as a follow up post on Code Coverage's future.

He starts off with the early days of Xdebug, how it hooked into the Zend Engine (that powers a lot of PHP behind the scenes) and when it was triggered. This came with its own set of problems so Xdebug was updated to overload some opcodes. He talks about how it can calculate the unused lines and determines which lines can be covered in the code coverage results. He provides some example code showing the execution of the coverage report on a simple function and try/catch handler, complete with the HTML output of the results.

tagged: xdebug codecoverage phpunit coverage history functionality opcode

Link: http://derickrethans.nl/code-coverage.html

NetTuts.com:
Refactoring Legacy Code: Part 9 - Analyzing Concerns
Jul 24, 2014 @ 11:27:56

The NetTuts.com site has posted part nine in their series sharing helpful hints and methods for refactoring legacy code. In this new post they continue on with their example application and look at where methods should be moved to/created and mocking in their tests.

In this tutorial, we will continue to focus on our business logic. We will evaluate if RunnerFunctions.php belongs to a class and if so, to which class? We will think about concerns and where methods belong. Finally, we will learn a little bit more about the concept of mocking.

They show how to move some of the "Runner" functions from procedural to OOP, integrating them with some of the classes and methods that already exist. Tests are also included showing how it all links together. From there they get into concerns about the placement of functionality and how that relates to the work at hand. They also use Mockery to mock out some of the needed objects in their tests for the new structure.

tagged: refactor legacy code series part6 concerns functionality mock unittest

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-9-analyzing-concerns--cms-21760

SitePoint PHP Blog:
Getting Started with PHP Underscore
Apr 17, 2014 @ 13:50:28

The SitePoint PHP blog has a new article posted showing you how to get started with Underscore, a PHP library ported over from Javascript's popular Underscore.js library with many of the same methods intact.

If you’ve ever used the Backbone framework for JavaScript, you’ll already be familiar with Underscore. Indeed, it’s become incredibly useful for JavaScript developers in general. But did you know that it’s been ported to PHP? [...] Underscore describes itself as a “utility belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It’s the tie to go along with jQuery’s tux, and Backbone.js’s suspenders.”

He starts by showing you how to get it installed and some of the basic syntax of the methods it defines (basically replace the period with the double-colon) for both the procedural and OOP handling. He shows examples of a few of the more handy methods it provides including:

  • Each
  • Pluck
  • Minimum and Maximum
  • Filter and Reject
  • sortBy
  • groupBy

...and many more. There's also a bit of talk about templating and extending the library via "mixins".

tagged: underscore port introduction methods functionality

Link: http://www.sitepoint.com/getting-started-php-underscore/

Jonathan Hill:
What Is Wrong With PHP's Semaphore Extension
Dec 14, 2012 @ 11:08:18

In this recent post to his site Jonathan Hill takes a look at the PHP semaphore extension and talks about some of the issues he's had with it.

He lists five different pain points he discovered when trying to use the extension:

  • Lack of a true Semaphore
  • Undefined error handling
  • Undefined behavior of sem_get()
  • Cannot disable semaphore auto-releasing
  • A semaphore may be deleted when other processes are waiting to acquire it

The semaphore extension provides a PHP-based wrapper for the System V IPC family of functions (including semaphores, shared memory and inter-process messaging).

tagged: issues semaphore extension systemv functionality

Link:

PHPClasses.org:
Lately in PHP, Episode 28 - Should PHP be Copying the Java features and practices?
Nov 13, 2012 @ 13:31:04

PHPClasses.org has posted the latest episode of their "Lately in PHP" podcast series - episode #29, Should PHP be Copying the Java features and practices?.

Particularly since version 5.0, PHP has been copying many of Java features and practices of Java programmers. This means that if Java programmers practices tend to be bureacratic and less productive, PHP programmers that use those features or adopt those Java practices may also become less productive. This was one of the main topics discussed by Manuel Lemos and Michael Kimsal on the episode 29 of the Lately in PHP podcast.

There's also a bit of discussion about adding generics to PHP and using OAuth in PHP. You can listen to this latest episode either via the in-page player, by downloading the mp3 or by watching the video of the recording. You can also subscribe to their feed to get the latest in the podcast series.

tagged: latelyinphp podcast java functionality oauth generics

Link:

Sherif Ramadan:
Test Drive PHP 5.5: A Sneak Peek
Oct 22, 2012 @ 12:09:02

Sherif Ramadan has a new post that gets into some good detail about what you can expect in the upcoming PHP 5.5 release with loads of new features.

There's been some talk about PHP 5.5.0 over the past couple of months even though it is barely on the horizon. The reason for this is that the PHP project has seen some increased levels of activity over the last two years since the dawn of PHP 5.4 and now in to the early twilight phase of PHP 5.5.0-dev. For those of you that haven't been following the internals mailing list I'm about to give you a quick test-drive and sneak-peak at PHP 5.5 using the latest 5.5.0-dev branch (which is still TBD).

Obviously, since the actual release of this version has yet to be determined, some of this may change over time. He gets into some of the major advancements and features that will be included like:

  • the "finally" keyword
  • list() support in foreach()
  • the Password Hashing API
  • generators
  • a new property accessor syntax
  • scalar type hints

Code samples are provided in some places to help make a bit more sense out of the example.

tagged: upcoming release version new feature functionality

Link: