News Feed
Sections




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

Knp University:
Symfony Service Expressions Do things you thought Impossible
May 06, 2015 @ 12:50:13

The Knp University site there's a new post showing you an interesting thing you can do with Symfony2 service definitions - use more complex expressions to load and supply service dependencies.

[Using] the @= means that you're using Symfony's Expression Language, which let's you mix dynamic logically into your normally-static service definitions. Normally, if you want to inject a repository, you need to register it as a service first, using a factory. And while that's fine (and probably better if you're injecting the factory a lot), using the expression language is well, kinda cool.

They include an example of the compiled container code that would be produced from the example expression. They also show how to use the same expression language to read configuration information and pass it in as an argument to the created service. The show the pull of a configuration setting "email_from_username" and how to inject it via the expression language.

0 comments voice your opinion now!
service expression language tutorial introduction configuration example

Link: http://knpuniversity.com/blog/service-expressions

Tech.MyBuilder.com:
Dependency Injection tutorial
May 06, 2015 @ 11:16:25

If you've heard the term "dependency injection" but are still a little fuzzy on the concept, you should check out this new post to the MyBuilder.com site introducing you to some of the basic concepts and using it in some PHP-based examples. They focus on the use of a dependency injection container in this tutorial (versus something like constructor or setter injection).

A lot has been written about dependency injection or DI (for short) in PHP, but it's a bit difficult to find a tutorial showing how a DI container actually works. The objective of this post is to show the internals and concepts of a DI container.

They start with a brief look at what a dependency injection container is and how it's different from a service locator or regular autoloading. They mention some of the benefits it provides and get into the simple example. They start with a class that creates a hard dependency in the constructor and show how to refactor that out to constructor injection. They then take the next step and replace the constructor injection with a DI container injection and how its internals are set up to provide new instances of requested objects (via a services definition).

0 comments voice your opinion now!
dependency injection di container tutorial introduction

Link: http://tech.mybuilder.com/dependency-injection-tutorial/

Reddit.com:
I feel like events are an anti-pattern
May 06, 2015 @ 10:55:00

On the /r/php subreddit frm Reddit.com, phpdevster proposes an interesting opinion - that an event system, set up with a listener and defined events, has become more of an anti-pattern in its most common implementation.

If events are only meant to be additional functionality that ALWAYS ALWAY ALWAYS should happen after a primary action is taken, how often is code really that absolute? Why are events not implemented in more flexible ways by frameworks? - that is implementing some inversion of control which would allow callers to determine which listeners would be relevant to the given context.

He illustrates his point with an example user registration system that fires a "user-was-registered" event that, in turn, fires off a series of events via a listener. He points out a pretty large flaw, though. While the functionality involved in the event is decoupled (the event itself), the behaviors defined by that event are not. Comments on the post offer some different options and solutions to the same problem including:

  • Further decoupling of the eventing process
  • Using objects with settable properties rather than just event name strings
  • The idea of using an "event store" to handle decoupling rather than more immediate code-based solutions

Have some thoughts of your own on events and decoupling? Go over and share them too.

0 comments voice your opinion now!
event antipattern designpattern reddit opinion comments

Link: http://www.reddit.com/r/PHP/comments/34zp6j/i_feel_like_events_are_an_antipattern/

Phil Sturgeon:
A Quick Note on PSR Numbering
May 06, 2015 @ 09:41:55

With a lot of talk happening around the PSR-7 HTTP request/response proposal and PSR-4 being the last "official" standard to be posted, some people are wondering what happened to PSR-5 and 6. Phil Sturgeon, a previous member of the PHP-FIG, has posted some clarification to how the PSR process works and where those seemingly missing PSR numbers are at.

The last PSR from the FIG to be sent out into the world, to be used by whoever felt like using it, was PSR-4: Autoloader. Now people are starting to hear about PSR-7, and they're starting to "lolphp", wondering what has happened to PSR-5 and PSR-6. [...] This is not like The Neverending Muppet Debate of PHP 6 v PHP 7, despite it being the first though to pop into many peoples heads. Instead, this is down to the Workflow Bylaw I put into place last year.

He goes on to talk about the current workflow stages and how, unlike systems in other languages, the PHP-FIG's process gives proposals a PSR number even before they're published and accepted. He also briefly talks about PSR "nicknames", naming to differentiate between similar proposals and how, despite the need for these names, they're just reference points for conversations more than anything.

0 comments voice your opinion now!
psr7 psr proposal workflow process numbering naming phpfig

Link: https://philsturgeon.uk/php/2015/05/05/psr7-numeric-workflow/

Nikita Popov:
Internal value representation in PHP 7 - Part 1
May 06, 2015 @ 08:12:27

Nikita Popov has a new post, the first part of a series, talking about the internal handling of variables in PHP7 and how it has changed from the current/past methods.

My last article described the improvements to the hashtable implementation that were introduced in PHP 7. This followup will take a look at the new representation of PHP values in general. Due to the amount of material to cover, the article is split in two parts: This part will describe how the zval (Zend value) implementation differs between PHP 5 and PHP 7, and also discuss the implementation of references. The second part will investigate the realization of individual types like strings or objects in more detail.

He starts with an introduction to the "zval" struct type and how it relates to the "zvalue" union. He goes on to talk about reference counting on zvals and some of the reasoning/desire to change how these are handled. Finally, he gets to the zval handling coming in PHP7 and the fundamental change in zval handling - they're no longer "individually heap-allocated and no longer store a refcount themselves". This change has several advantages and including improved refcount handling and less pointers involved in determining the actual value. He includes an example of how this new zval structure is defined in PHP7 compare to the previous version too. The remainder of the post looks at other related issues including memory management, supported types and a major change to how variable references are handled.

0 comments voice your opinion now!
internal value variable representation php7 zval zvalue memory reference

Link: http://nikic.github.io/2015/05/05/Internal-value-representation-in-PHP-7-part-1.html

Community News:
Recent posts from PHP Quickfix
May 06, 2015 @ 07:01:48

Recent posts from the PHP Quickfix site:
0 comments voice your opinion now!



Web Development Blog:
Add a MailChimp subscribe feature to your contact form
May 05, 2015 @ 12:14:13

The Web Development Blog has a tutorial posted showing how to add a Mailchimp "subscribe" feature to your current contact forms. They make use of the MailChimp API wrapper library to make the calls back to the service and subscribe the user at their request.

MailChimp is a great email marketing service provider with an easy to use control panel and features like: campaign management (RSS-driven, A/B Split, Plain-text and regular), statistics, auto-responder and a complete set of list management tools. They offer different ways to place a subscriber form on your website or blog. If you to like add the MailChimp subscribe feature to your existing contact form you need to add some custom code.

They start with a few things you'll need to do to prepare for the connection including the setup of an API key to make the request. He provides a simple "Contact Us" form for reference and the code needed on submit to validate the input and make the subscription call to the API with the email the user provided. He also includes a bit of response handling.

0 comments voice your opinion now!
mailchimp tutorial subscribe contactus form api request

Link: http://www.web-development-blog.com/archives/mailchimp-subscribe-contact-form/

SitePoint PHP Blog:
Automatic PHP Code Generation with Memio
May 05, 2015 @ 11:52:07

On the SitePoint PHP blog a new tutorial shows you how to generate code with Memio, a relatively new PHP-based tool that lets you define "models" as structures for the code you need generated.

Ever thought of writing code responsible for generating certain PHP classes, methods, properties automatically? Read on to get the details on when exactly automatic code generation may be helpful and - what's most important - how to implement it properly using the Memio library.

He starts with a bit of introduction to the basic concept of code generation and mentions a few places it's currently used. Then he gets into the examples, starting with a bit of code showing how to get Twig loaded and injected into the Memio instance. From there he shows a simple example of creating a class with a single method and single line of code. With the basics understood, he gets into a more "real world" example of generating ORM classes with getters and setters for the different properties/column names.

0 comments voice your opinion now!
tutorial generate code memio library example orm realworld

Link: http://www.sitepoint.com/automatic-php-code-generation-memio/

Michelangelo van Dam:
popen for cli commands and pipes in php
May 05, 2015 @ 10:53:38

Michelangelo van Dam has a quick new post to his site talking about popen and pipes in command-line PHP as an alternative to the "exec" functions PHP provides to make command lines calls.

I got a question today about using commands that pipe output to other commands within PHP applications. There are two functions in PHP that are perfect for the task: popen and proc_open. But when you want to run it as a complete process, you can go about using exec, shell_exec, passthru or system and fiddle with escapeshellcmd. But often this looks messy and not reusable. A better approach would be to use "popen".

He includes a code example of how to use this method, showing a call to a command line tool and piping the results back into a PHP variable for later use. You can find out more about the use of popen in the PHP manual and accompanying examples.

0 comments voice your opinion now!
popen procopen commandline cli pipe result example

Link: http://www.dragonbe.com/2015/05/popen-for-cli-commands-and-pipes-in-php.html

Marc Morera:
Visithor, Testing Your Routes Without Pain
May 05, 2015 @ 09:25:57

In his latest post Marc Morera shares a new tool he's created to help with testing routes for specific HTTP code responses and other attributes of your "HTTP layer" - Visithor.

Many years ago I was thinking about a simple and fast tool to test specific routes, expecting specific HTTP codes and providing an easy environment of ensuring properly your HTTP layer. So… I present you Visithor, a PHP based library that provides you this functionality, with a simple configuration definition and a very easy way of installation.

He starts with a few quick commands to get the library installed (either globally or local to the project) and how to create the first configuration file. This file defines the tests to execute as a set of URLs with allowed HTTP response codes. He also shares a Symfony2 bundle that can be used to integrate it with your current application, allowing for more flexibility in route check configuration and environment settings. He also includes a quick example of integrating it with your Travis-CI build as a "script" command to be executed.

0 comments voice your opinion now!
visithor library testing http response code symfony2 bundle integration

Link: http://mmoreram.com/blog/2015/05/04/visithor/


Community Events

Don't see your event here?
Let us know!


composer community series voicesoftheelephpant opinion release symfony2 introduction podcast framework laravel performance extension interview api conference version example php7 library

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework