2012年9月28日星期五

Site News: Popular Posts for the Week of 09.28.2012

Popular posts from PHPDeveloper.org for the past week:

Josh Adell: Interfaces and Traits: A Powerful Combo


Josh Adell has a new post today looking at the "powerful combination" of using traits and interfaces in PHP applications. He shows how, despite traits not implementing the interface directly, they can be used to make other classes adhere to them simply by "using" them.



If you're not using interfaces in PHP, you are missing out on a powerful object-oriented programming feature. An interface defines how to interact with a class. By defining an interface and then implementing it, you can guarantee a "contract" for consumers of a class. Interfaces can be used across unrelated classes. And they become even more useful when combined with the new traits feature in PHP 5.4.


He illustrates with a package shipping example and uses an "Addressable" Interface to define the structure for both a Company and Users class. He includes code showing how to implement it in a more traditional "implements" way in a class, but also shows an interesting way to achieve the same thing with traits. Having a trait that follows the interface makes it easy to have a class adhere to the interface just by including the trait (or "using" it).

NetTuts.com: All About Mocking with PHPUnit


NetTuts.com has another post for those out there wanting to further their PHP unit testing knowledge. In this new tutorial, Csaba Patkos introduces you to mocking objects with PHP Unit - a powerful method to help test some of the more difficult things.



There are two styles of testing: "black box" and "white box" styles. Black box testing focuses on the object's state; whereas, white box testing focuses on behavior. The two styles complement each other and can be combined to thoroughly test code. Mocking allows us to test behavior, and this tutorial combines the mocking concept with TDD to build an example class that uses several other components to achieve its goal.


He illustrates mocking with his sample "toy car" application and shows how to use a few different types of mocks (test doubles) to create some tests. These types include dummy objects, test stubs, test mocks and test fakes. Code is included for all test examples, including some showing the use of the actual PHPUnit mocking functionality.

Reddit.com: PHP and Continuous Integration


On Reddit.com there's a recent post answering a question asked about PHP and continuous integration during a project's development.



Does anyone have experience with PHP and Continuous Integration? If so, what tools and / or platforms did you use?

Suggestions in the comments include:


2012年9月27日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

Gary Hokin: An Introduction to Zend Framework 2 for the Zend Framework 1 Developer - Part 1


Gary Hokin has posted the first part of a series he's doing to introduce those Zend Framework v1 developers out there to the latest version of the framework, Zend Framework v2.



Having worked with ZF1 for a lot of years, I've been watching the development of ZF2 with interest. I've tried nearly every version, from the heady days of the pre-Skeleton App, right through the betas and release candidates. With the imminent release of ZF2 proper, I thought I would share with you some of the most obvious differences between ZF1 and Zf2. Of course, these are only my opinions. While I've contributed (lightly), I've learned most of my ZF2 knowledge from hanging around in IRC and badgering people. If you want to learn quickly and have no remorse for annoying others, you should too!


He covers three of the main differences between the two, namely the namespacing support to replace the awkward class naming, the module-based approach and how bootstrapping is handled. There's a few code snippets tossed in for clarity and a look ahead to the second part for what's to come.

Codeception Blog: The Locator Class


The Codeception blog (a BDD testing tool) has a new post on using their Locator class to create more complex tests based on XPath or CSS selectors.



In the latest Codeception 1.1.4 new Locator class was introduced. Basically it should simplify your life in writing complex XPath or CSS locators. Right now it has minimal, yet useful functionality.


The post shows how to combine more than one item for location with either a tag, CSS-based or XPath-based selector. It also shows how to use the "tabindex" method to simulate the movement through a page using the "Tab" key. Finally, there's a quick piece of code showing how to locate an item based on the "href" value. For more information on using Codeception, check out their documentation or the project's main site.

NetTuts.com: Hands-On Unit Testing With PHPUnit (Screencast)


On the NetTuts.com site today there's a new screencast posted (by Jeffrey Way) that gives you a hands-on look at using PHPUnit to write and execute tests on your code.



In this screencast, we'll build a relatively simple class, using TDD techniques. Along the way, we'll discuss various PHPUnit methods, how to create mock objects, and more! I encourage you to work along; it's the best way to learn!


If you're new to unit testing this is a good way to start. He uses the Laravel framework as a base for the testing and a TDD (test-driven development) approach. Once you've gotten your feet wet following along with the screencast, you can go over to the PHPUnit site for more details.

2012年9月26日星期三

Community News: Latest Releases from PHPClasses.org

Ulf Wendel: Not only SQL injection: I don't trust you!


On his site today Ulf Wendel talks about SQL injection and some comments that came up during a recent webinar about common MySQL mistakes PHP developers make.



Never trust user input! Injection is a threat . You are the new web developer, aren't you?. Never trust user input is the first rule I had to learn as a web developer in anchient times. Injection can happen whenever user input is interpreted or used to compose new data. A quick recap of the #3 mistake from todays Top 10 MySQL Tips and Mistakes for PHP Developers web presentation. A webinar recording should be available in a couple of days.


He points out a few "don't" things to avoid - like directly injecting superglobal values into your query and to remember that not all SQL injections are because of escaping issues. The real key? Validating input - be sure you're putting values into your query that are of the correct type and contain what you expect.

Ars Technica: Questions abound as malicious phpMyAdmin backdoor found on SourceForge site


As Ars Technica reports, there was a recent exploit found on the SourceForce website's installation of phpMyAdmin that allowed an attacker to POST anything to the site to be executed.



Developers of phpMyAdmin warned users they may be running a malicious version of the open-source software package after discovering backdoor code was snuck into a package being distributed over the widely used SourceForge repository. The backdoor contains code that allows remote attackers to take control of the underlying server running the modified phpMyAdmin, which is a Web-based tool for managing MySQL databases. The PHP script is found in a file named server_sync.php, and it reads PHP code embedded in standard POST Web requests and then executes it. T


The backdoor was somehow snuck into the code of phpMyAdmin on one of the mirrors and distributed to those downloading version 3.5.2.2. They think that the only downloads that were tainted with this issue were on the "cdnetworks" mirror site. You can find out more about the issue in this advisory - be sure you check your installation for a "server_sync.php" file and remove it if it exists.

Thomas Hunter: CouchDB and PHP Web Development (Book Review)


Thomas Hunter has posted a (nice long) book review of the Packt Publishing book "CouchDB and PHP Web Development" to his site.



When I first picked up this book, I was expecting a boring, text-book approach to code examples for PHP talking with CouchDB. Boy was I wrong. What I found was a book that has you build a complete working application. And by complete, I mean you'll add the Twitter Bootstrap framework and it will be sexy.


He mentions parts of the app you'll create - a PHP framework, 3rd party libraries, working with git/github - and goes through the sections of the book, talking about good and bad points along the way. Chapters cover things like: an introduction to NoSQL, REST/HTTP verbs, installation/config of CouchDB, using version control and deploying the app using the PHPFog PaaS hosting.

2012年9月25日星期二

ScreenFony.com: Work with bootstrap, assetic and less


On the ScreenFony.com site there's a quick tutorial showing you how to get started with Symfony2+Twitter Bootstrap+Assetic+LESS in a basic application. Assetic is a library that helps with asset management and use and LESS is a CSS pre-processor that makes it simpler to work with your site's CSS.



Bootstrap is a well known and powerful front-end framework for fast prototyping, it uses LESS and it can be easily integrate in your Symfony applications with the help of assetic. In this post I'll show how to: Install bootstrap in you Symfony application, load it using assetic, and compile bootstrap LESS files with lessphp.


Using Composer, creating a new Symfony2 project is just a single command away. The just update the "composer.json" and run the install to get the other needed libraries (LESS and the Twitter Bootstrap). They help you set up some Assetic filters for LESS and provide a simple page to output the Bootstrap in your header.

2012年9月24日星期一

Community News: Latest PEAR Releases for 09.24.2012

Latest PEAR Releases:

7PHP.com: Interview with Eli White, CTO of Musketeers.me


On the 7php.com site today they've posted the latest PHP community member interview - this time it's with Eli White, the CTO of Musketeers.me (the group behind MojoLive).



In this edition I talked with [Eli White @EliW], who is currently the Founding Partner and Chief Technical Officer Of Musketeers.me - a consulting firm. Eli was previously the CTO at the social career management platform known as mojoLive and has been working for numerous famous high profile web projects, namely Digg and TripAdvisor amongst others. He was also (back in 2009) the PHP Community Relations Manager and DevZone Editor-in-Chief for Zend Technologies Inc. Elliott White is also the author of the PHP book - PHP 5 in Practice and has attended 30 conferences (at the time of this writing) in which he was a presenter for 49 sessions.


In his answers, Eli talks about things like:



  • Some of his interests outside of programming (like Medieval Reenactment)
  • What he sees as the current "good parts" and "bad parts" of the PHP language
  • He recommendations of resources for PHP beginners
  • Software he recommends (testing, CMS, e-commerce)
  • The best way he sees to get involved in the community (conferences, user groups, etc)

Scott Mattocks: L is for Logging (LUCID)


Scott Mattocks has started off his series about the LUCID development methodology (one he recently proposed) with the first article covering "L" for Logging.



Communication is the only way you can tell if an application is feeling well or is about to fall apart. If your application can't talk to you, you have no way of helping it to feel better. The L in LUCID is for logging. Logs are how applications speak. They capture information that allows us to pick up on those little signs and act early enough to make sure the application doesn't come down with the flu. If you don't have good logging throughout your system, the best you can do is react to your application falling over. A silent application is an application destined to cause midnight surprises for you and your operations team.


He talks about the difference between "just logging" and "correct logging" as well as a recommendation for the different levels: trace, debug, info, warn and error.



Letting you know that something went wrong is really only half of a log messages job. The other responsibilities of a log message are to allow you to accurately reproduce the conditions under which the event occurred, and to allow you to fix any data inconsistencies.

PHPWomen.org: One way to handle concurrency in a multi-user web app


In this new post to the PHPWomen site, Kim Rowan shows one way that you can effectively handle concurrency in your applications (in her case, a Symfony app).



Concurrent user activity on the web can take many forms. For example, two online shoppers may simultaneously try to buy the last pair of 'gotta-have-em' shoes in stock. Presumably one potential outcome in this scenario is to place the shoes on back-order for the slower shopper. The concurrency challenge I faced recently, however, was a bit different...


She uses a "last updated" data field in her form to see when the record in question was last changed. When the form is submitted the script checks against the updated date on the record to see if it's later than the one submitted. If it's more recent, the user's request could cause errors, so it fails.

2012年9月21日星期五

Site News: Popular Posts for the Week of 09.21.2012

Popular posts from PHPDeveloper.org for the past week:

Cory Fowler: Enabling PHP 5.4 in Windows Azure Web Sites


Cory Fowler has a recent post explaining how you can enable one of the most recent PHP releases (PHP 5.4) on your Windows Azure website via the " Bring-Your-Own-Runtime" feature.



Much like many other developers, I like to live on the bleeding edge, learning new language features, using the latest tools so naturally one of the things I wanted to see in Windows Azure Web Sites is support for PHP 5.4. I'm pleased to be telling you today in this post that support for Bring-Your-Own-Runtime is now available in Windows Azure Web Sites. Out of the box, Windows Azure Web Sites supports PHP 5.3 as you can see from the snapshot of the portal below. In this article I'll explain how to enable PHP 5.4 in Windows Azure Web Sites.


You'll need to set up and configure an Azure instance to work with (if you don't already have one) and navigate to its management Dashboard once complete. You can then setup a handler mapping that points to an uploaded version of the PHP Windows binary for 5.4 on your document root. Then all that's left is to upload (via FTP or git) this executable and you'll be all set.

Tecmint.com: Install Apache, MySQL 5.5.27 & PHP 5.4.7 on RHEL/CentOS 6.3/5.6 & Fedora 17-12


Tecmint.com has a new tutorial that walks you through the installation of a full LAMP stack (Linux, Apache, MySQL and PHP) on a CentOS or RedHat installation.



This howto guide explains you'll how to install Apache Server with latest MySQL 5.5.27 and PHP 5.4.7 versions with php required following modules on RHEL 6.3/6.2/6.1/6.0/5.8/5.6, CentOS 6.3/6.2/6.1/6.0/5.8/5.6 and Fedora 12,13,14,15,16,17 systems using Remi repository via Yum tool.


Thankfully, package management has made things a lot simpler than they used to be. Most of the time you're only a few commands away from a working installation (if all you need are the generic setups). They explain what each piece of the installation is and how to set up the custom "Remi" yum repository to get the latest versions of the software - Including PHP 5.4. They show how to stop and start each of the servers (MySQL, Apache) and a few screenshots of what the output of your phpinfo page should look like.

Community News: Atlanta PHP October Meeting - Jacob Terry on Tracking in Applications


The Atlanta PHP User Group has announced their October meetup with a presentation from Jacob Terry about tracking in your application.



Even if your users don't want a full "audit trail" of activity, even if you aren't interested in doing a newsfeed, recording user actions in your application can be enormously useful. We'll look at a real-world implementation of recording that data, using a CodeIgniter-based application, and discuss three less-obvious use cases. Those are: Undo, Sync & Emails.


The meeting is going to be on Thursday, October 4th from 7-9pm at the Strongbox West coworking facility. If you're in the Atlanta area, you should definitely check this group out!

Michael Maclean: Why one-line installers are a bad idea


There's a feature that's usage has been showing up more and more in software projects (both open source and not) that allows you to install their system with a single line command, usually involving curl and maybe piping it to a shell. In this recent post Michael Maclean takes a look at this trend and some of the possible pitfalls of the approach.



There has been a trend in the last while for various bits of useful software to have a one-line shell command recommended as the installation method. The usual form of this is to pipe something like curl or wget to some interpreter, be it bash, php, ruby, or some such. [...] This [type of] command takes the output of curl and pipes it straight to bash. I have several issues with this.


His three main points center around the fact that you cannot inspect the code before executing it with this method, that you can't verify the source of the code and that it teaches users bad habits of trusting in "magic commands" like these.

2012年9月20日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

David Müller: Why URL validation with filter_var might not be a good idea


David Müller has a new post to his site today showing why validating URLs with filter_var is a good thing for the security of your application.



Since PHP 5.2 brought us the filter_var function, the time of such [regular expressions-based] monsters was over. [With] the simple, yet effective syntax [and] with a third parameter, filter flags can be passed, [...] 4 flags are available [for URL filtering].


He shows how to use it to filter out a simple XSS issue (a "script" tag in the URL) and some examples of issues that the filter_var function doesn't prevent - like injection of other schemes (like "php://" or "javascript://"). He recommends adding a wrapper around the method to check for the correct scheme (ex. "http" or "https" for URLs) and reminds you that filter_var is not multibyte capable.

Matthew Weier O'Phinney: ZF2 Modules Quickstart (Screencast)


Matthew Weier O'Phinney has put together a screencast showing you how to get up and running (a quickstart) with the latest release of Zend Framework 2.



One of the exciting features of the newly released Zend Framework 2 is the new module system. While ZF1 had modules, they were difficult to manage. [...] In Zend Framework 2, we've architected the MVC from the ground up to make modular applications as easy as possible. [...] To give you an example, in this tutorial, I'll show you how to install the Zend Framework 2 skeleton application, and we'll then install a module and see how easy it is to add it to the application and then configure it.


The screencast (also viewable over on Vimeo) talks you through all the steps in the process, but the code is also provided in the post along with screenshots of how the application should look at various steps.

PHPMaster.com: Compiling PHP from Source on Windows


For most PHP developers, when they hear "compile from source" they automatically assume that the person talking means they're working with a unix variant-based system. In this new tutorial from PHPMaster.com, though, they show how to "compile from source" on a different platform - Windows.



Those working in a Windows environment are more likely to download and install PHP from precompiled packages. And while I don't disagree it's easier to use a precompiled solution, even on Unix systems, there are some advantages that can come with compiling a binary from source. [...] But be forewarned: compiling can be a frustrating task, especially on Windows! You must ensure your build environment is set up correctly, learn how to use the compiler and other build tools properly, and satisfy any library dependencies. Hopefully this article is your first step in overcoming many of these obstacles.


The tutorial walks you through the steps you'll need to take to get your environment set up, including the tools you'll need to be able to perform the compile (including Microsoft's Visual C++ Express and the Windows Software Development Kit). Screenshots and commands are all included in the post to make the compile work. There's even a few instructions on compiling in the extensions you might need.

2012年9月19日星期三

Community News: Latest Releases from PHPClasses.org

Chris Risner: Mobile Geolocation Apps with Windows Azure Websites Part 1: The PHP Code


Chris Risner has posted the first part of his series looking at mobile geolocation in PHP-based Azure applications as hosted on the Windows Azure service.



The first article in this mini-series on creating geolocation apps with the backend hosted in Windows Azure Websites is going to be a walkthrough of the PHP code that we'll host in Windows Azure. The PHP site will be simple and expose just a few methods. Prior to getting into the code for the service, we need to setup a new website in Windows Azure and set up our database.


He walks you through some of the initial steps to create the PHP side of things - setting up the website instance and database, downloading the Silex PHP framework and the PHP code to get process the latitude and longitude of the current user. Also included is code to help find "interesting" points near the user and code to allow the user to add their own.

Miro Svrtan: Starting/organizing a developer community: ZgPHP meetup


In a recent post Miro Svrtan talks about a PHP developer community he started up in the Zagreb, Croatia area, the ZgPHP user group, and some of the lessons he learned in the process.



The year 2011 was a great success for developer communities in Zagreb. Although mobile developers started in 2010 with Mobile Monday, web developers were a bit shy and Ruby developers started first, then python meetups started and in the summer few people urged/pushed me to start organizing PHP Meetups. Besides colleagues I did not know a lot of PHP developers so I needed to spread the word about it. Twitter was the first step and it paid off. With only a few retweets there were already 10-20 people interested.


The post talks about the growth of the group, things they wish they'd done better (like involving local companies) and their work to create a custom logo for the group. If you're in the area and want to find out more about the group, check out their main page.

Community News: PHPUnit Now Available via Composer


In case you missed the tweet where it was mentioned, thanks to some work from Clay Loveless, the popular PHP unit testing tool, PHPUnit, can now be installed via Composer.



Thanks to this pull request on the project, adding PHPUnit to your project (and its dependencies) are a few simple commands away:



The package-composer.json file, coupled with package.xml and the package2composer script that is part of the Conductor package at http://pear.claylo.com/ is all that is needed to update the composer.json file. Simply run package2composer in the top level of the checkout to regenerate composer.json to reflect changes made to package.xml


If you're not using PHPUnit to test your code currently, you can find out more about it and its use in the current manual.

2012年9月18日星期二

Community News: Latest PECL Releases for 09.18.2012

Latest PECL Releases:

PHPMaster.com: Using the Last.fm API


New on PHPMaster.com today there's a tutorial showing you how to work with the Last.fm API from your PHP applications (a REST-based service). Last.fm is a social music site and recommendation service that takes what you already listen to and suggests other artists/songs you might like.



If you are building a site for a band or artist and you want to make it more social using Last.fm, it's a must to use their API. In this way artists and fans can become connected and fans can stay up to date on concerts and new albums. In this article I show you how to query the Last FM API to get information to build a fan website for Coldplay. We start with getting the basics about the band, then get their most popular song, the contents of their albums, and a list of the events where the band is going to play for fans to get tickets.


They show you how to use the Last.fm API library to work with the service, extracting data about the bad including basic descriptions, upcoming events, top tracks and album information.

DevHell Podcast - Episode 19: Almost an Apology


The latest episode of the /Dev/Hell podcast has been posted today - Episode #19, "Almost an Apology". Hoest by PHP community members Chris Hartjes and Ed Finkler, their special guest this time is Chris Shiflett.



After some downtime spent taking mental reps, Chris and Ed are back with a vengeance for one of our best shows. Joining us is Chris Shiflett, PHP fellow and security expert. They talk about how we interact with non-techie members of dev teams, what they're doing with Node, the state of the Canadian soccer program, heavy vs lightweight frameworks, tribalism in programming communities, and the importance of balancing work with life. We also talk to Chris Shiflett about his role as co-founder of Brooklyn Beta, and what they aree trying to do with the conference.


You can listen to the episode either using the in-page player, by downloading the mp3 or by subscribing to their feed.

Danne Lundqvist: Using Xdebug in MAMP


Danne Lundqvist has a new post today showing you how to install and use XDebug with MAMP, the popular all-in-one LAMP package for OS X.



MAMP is a full local server environment including Apache, PHP and MySQL in one package. Anyone feeling at home in *nix systems should feel at home using both OS X and MAMP. [...] As I have helped a few collegues setup Xdebug in MAMP I have discovered that a lot of developers don't do this as they don't know how simple it is. Even seasoned PHP developers use the old echo/die debugging techniques.


He includes all the changes you'll need to make to configuration files and makes a simple script you can use to test out that things are working. As his IDE of choice is PHPStorm, he shows how to set up the remote debugging to work and reply back as the script is executed.

2012年9月17日星期一

7PHP.com: Interview with Matthew Turland, Co-Author of "PHP Master: Write Cutting Edge Code"


7PHP.com has posted another interview with a PHP community member - this time it's with Matthew Turland, one of the co-author's of SitePoint's "



In this edition I talked with [Matthew Turland
@elazar], co-author of the PHP book 'PHP Master:Write Cutting Edge Code'. He currently works as a Senior Platform Engineer for Synacor Inc. Matthew was also a former technical editor for php|architect Magazine, contributor to the Zend Framework project and has spoken at conferences like ZendCon and php|tek. On the FOSS side, Turland is the man behind the Phergie project - a PHP-based IRC bot.

His answers talk about things like:



  • What kind of environment (and tools) he uses for his development
  • His work on the Phergie IRC bot project
  • Resources he recommends for those new to the language
  • What software he recommends/appreciates
  • Some of the good and bad about conferences he's attended
    And a recommendation to check out the PHP Mentoring project for more guidance

Justin Carmony: Vagrant & PHP: Our Success Story at the Deseret News


Justin Carmony has shared his success story about the use of Vagarant and PHP as a platform to make setting up and configuring developers' environments simple.



Now-a-days, you have frameworks that need to be setup [as a part of your environment], include paths that need to be changed, modules that need to be installed, web servers that need to be configured for your routing, etc. Then you might not just have MySQL, but Redis, Mongo, Couch, Memcached, Postgres, or any other dozen other servers. Then in Production you might have load balancers, multiple web servers, clusters of databases, and the list goes on. Simply put: web development environments are complex.


He introduces Vagrant and talks a bit about how it helped them with the setup and configuration of two new remote developers they had limited contact with. After some initial quirks, Vagrant made it simple for them to get up and running with new environments in a day.

Rob Allen: Module specific layouts in ZF2


Rob Allen has a new post to his site about module-specific layouts in Zend Framework 2 via a module from Evan Coury.



If you need different layout scripts to be rendered for different modules in Zend Framework 2, then Evan Coury has made this extremely easy. His new module EdpModuleLayouts is just the ticket! Once installed, you simply have to add a new array to a config file in the config/autoload folder.


The update is just a simple "module_layouts" setting that lets you specify it based on the module name by giving it a layout path, He explains the script a bit more in the comments and points to this other post for more information about modules handling their own layouts.

Robert Basic: Unit testing Zend Framework 2 modules


Robert Basic has a new post showing you how to create unit tests for modules in your Zend Framework 2 applications. His example includes how to set up PHPUnit and how to write a few sample tests.



Porting this blog to Zend Framework 2, I decided to write some unit tests as well, while I'm at it. Not that the current code base doesn't have unit tests, just it doesn't have much of it... Anyway, I'd like to show how to get unit tests for modules up and running, as well how to throw in Mockery in the mix, as it can help us greatly with mocking out objects.


He includes the sample "phpunit.xml" configuration file contents, a "bootstrap.php" file to correctly initialize all the resources you'll need (including Mockery) and two kinds of tests - one on the service layer and another on the database layer.

2012年9月14日星期五

Site News: Popular Posts for the Week of 09.14.2012

Popular posts from PHPDeveloper.org for the past week:

PHP.net: PHP 5.4.7 and PHP 5.3.17 released!


On the PHP.net site they've announced the latest releases of the language - PHP 5.4.7 and 5.3.17:



The PHP development team announces the immediate availability of PHP 5.4.7 and PHP 5.3.17. These releases fix over 20 bugs. All users of PHP are encouraged to upgrade to PHP 5.4.7, or at least 5.3.17. Key enhancements in these releases include bugs #62955 and #62460.


If you'd like to see the full list of changes you can see them in the Changelog. To download this latest release you can head over here: source downloads, Windows downloads.

Reddit.com: What does it take to be hirable in the world of PHP?


On Reddit.com there's a new discussion about what it might take to be "hirable" as a PHP developer and recommendations from the community as to things to do.



I'm a 19-year-old who has recently hit a bit of a rough spot in life, and the only real skill I have other than tending the cash register is programming. I've been programming for quite a while, although I've never taken more than small web design work in terms of paid jobs. I'm interested to know if with some touch-up and extra learning PHP is something that's realistic for a young person to be looking at for a career, or at least an interim step in life.

There's several different kinds of suggestions including:



  • They may consider relocation as a viable option
  • Learn MVC and related technologies
  • Find a local meetup and network
  • Learn about the most up to date techniques (namespacing, wriitng secure code, etc)
  • Make a publicly available code repository with samples of your work
  • Look for an open source project to contribute to

Emanuele Minotto: PHP in a Tweet


Emanuele Minotto has a recent post with a set of "PHP in a tweet" posts that do all sorts of things.



Yesterday an ex colleague tweeted something that captured my attention, so I started thinking to a Twitter-powered code golfing competition. Looking for other examples.

Tweets included in the list are snippets like:



  • A dependency injection container
  • A super simple web framework
  • A microframework
  • Bypassing array_intersect


There's some game rules included in the post so you can contribute your own to the the comments. Several have already been added including a base64 encoding variant and getting the extension of a file.

2012年9月13日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

Sebastian Göttschkes: symfony2: Testing email sending


Sebastian Göttschkes has a new post showing a method he's come up with to test email sending in a Symfony2 application.



On my endless struggle to achieving 100% code coverage and catching every possible (and impossible) test case (I'm just kiddinh, please don't do this!) I was in need for some way to test the sending of emails. This blog post will show you how to test this within a symfony2 (I'm using symfony 2.1 RC2) application, using the default swiftmailer.


It's not unit testing, it's functional testing, and he provides a bit of background on the process first then sets up a dummy listener for testing and how to plug in the Symfony2 functionality (via a getContainer call to get the DIC).

CodeIgniter.com: Rumbelow Publishes Volume Two of CodeIgniter Handbook Series


On the CodeIgniter blog there's a new announcement about a book published from one of the main CodeIgniter developers (Jaime Rumbelow) - the second volume in the CI Handbook series.



Earlier this year I wrote and released The CodeIgniter Handbook - Vol. 1 - Who Needs Ruby? to critical acclaim. It's been several months since the release of Volume One and everybody's support, feedback and enthusiasm has been absolutely wonderful. To everyone who has purchased a copy, thank you. I'm thrilled to announce that Vol. 2 - API Design, was released last week and is now available to purchase in PDF or Paperback.


This new book covers API design and how you can make your app "connected" in an automated world. If you'd like to pick up a copy of this new book, you can get one from efendi books.

Jim Bird: How to Cheat at Application Security


Jim Bird has a new post with links to a few different resources helping you "cheat" at application security - links to cheat sheets with highlights of key points to keep an eye out for.



Developers need to know a lot in order to build secure applications. Some of this is good software engineering and defensive design and programming - using (safe) APIs properly, carefully checking for errors and exceptions, adding diagnostics and logging, and never trusting anything from outside of your code (including data and other people's code). But there are also lots of technical details about security weaknesses and vulnerabilities in different architectures and platforms and technology-specific risks that you have to understand and that you have to make sure that you deal with properly. Even appsec specialists have trouble keeping up with all of it.


He links to several of the OWASP cheat sheets for things like:


PHPMaster.com: Amazon DynamoDB: Store PHP Sessions with Load Balancer


PHPMaster.com has a new tutorial posted showing how you can work with the Amazon DynamoDB to store session information from your PHP application (originally posted on CloudSpring).



This tutorial will show you how to use Amazon DynamoDB as a storage facility for PHP sessions. This method becomes very useful when your applications take advantage of the Elastic Load Balancing and Autoscaling services. You will need Amazon AWS account enabled to use EC2, Elastic Load Balancer and DynamoDB as a prerequisite to play along the tutorial.


He starts with a description of what the elastic load balancing service is and how it autoscales. He shows how, based on this demo application, to use a custom PHP session handler that implements the Amazon SDK libraries to hook into the DynamoDB service. Also included are screenshots (and the steps that go with them) to configure the service itself.

2012年9月12日星期三

Community News: Latest Releases from PHPClasses.org

Scott Mattocks: LUCID Development


Scott Mattocks has a new post to his site today about a set of development principles he's proposing called "LUCID" (similar in idea to SOLID) - Logs, Unit Tested, Configurable, has Isolated features and is fully Documented.



Building software with a clear set of use cases and requirements is a relatively straight forward process. Various design patterns exist to help you solve problems which others have come across already. You can use principles like SOLID to help separate your classes and simplify your code. [...] Using a set of guidelines like SOLID may make it easier to swap out a broken class for a new class, but they don't really help you identify the problem or fix any data corruption which may have occurred. Knowing you have a problem and being able to isolate and fix the problem is just as important, if not more so, than being able to rely on consistent interfaces from your factory method. That is why I am proposing an additional set of software development guidelines called "LUCID code."


He defines it as "code with understands that bugs are unavoidable" and is able to give developers feedback through its own logging, tests and documentation. With correctly isolated code, development can be segmented and worked at the same time and make changing requirements and updating functionality simpler in the long run.

Robert Basic: Working with custom view helpers in Zend Framework 2


In his latest post Robert Basic looks at working with custom view helpers in your Zend Framework 2 application and shows how to implement a simple one to display a simple greeting.



I took the skeleton [Zend Framework 2] application, made it even skinnier by throwing out some (for me) unneeded parts and just put it all besides my old ZF1 code. [...] The first problem I ran into was using custom view helpers, especially view helpers that are more general and don't fit into one specific module. Where to put the code? How to access them in views? The second problem was how to access the service manager from a view helper? And the third problem was how to tell the helper to use a specific value when inside a specific module?


He includes a simple example - the greeting helper - and shows where to place it in the application structure, how to work with the service locator inside it and how to set up some module-specific views inside.

NetTuts.com: Evolving Toward a Persistence Layer


On NetTuts.com there's a new article posted that introduces you to the concept of a persistence layer in a PHP application:



One of the most confusing design pattern is persistence. The need for an application to persist its internal state and data is so tremendous that there are likely tens - if not hundreds - of different technologies to address this single problem. Unfortunately, no technology is a magic bullet. [...] In this tutorial, I will teach you some best practices to help you determine which approach to take, when working on future applications. I will briefly discuss some high level design concerns and principles, followed by a more detailed view on the Active Record design pattern, combined with a few words about the Table Data Gateway design pattern.


Included in the post is a high-level application design with the business logic is at the core and the persistence technology/layer exists outside of it. They show how to create a simple, working solution for a persistence layer to handle a blog post and its contents. It talks about characterization tests, the table gateway design pattern and the possible move to the active record pattern.

2012年9月10日星期一

PHP7.com: Interview with Ian Barber, Developer Advocate with Google+


On php7.com today they've posted the latest in their series of PHP community interviews - this time it's a chat with Ian Barber, a developer advocate for Google+.



In this edition I talked with Ian Barber
@ianbarber who is a developer advocate for Google+. Ian has been working with PHP for Virgin in the UK and has an amazing run of experience in the PHP world; delivering presentations at a number of conferences - his recent talk entails "Building a Firehose" at [PHP Tek 12 @mtacon].


In the interview Ian answers questions about:



  • How he got started with PHP
  • What he considers the good/bad parts of PHP
  • The tools that he uses for his development
  • Which user group he's a part of
  • Some of the things he's learned being a part of the PHP community


You can read the rest of the interview here.

Community News: All Your Base Conference - Databases for Web Developers


John Wards passed along some information about an upcoming one-day conference happening in Oxford (UK) during the end of November (the 23rd), a conference aimed at developers but talking mostly about database both server and client-side - the All Your Base Conference.



The All Your Base Conference is a database conference for web developers. It's a one day affordable, single track conference exploring noSQL, RDMS and client-side database solutions. There will be a keynote from the creator of MySQL Monty Widenius and talks from developers from Github, Heroku, Adobe, Mozilla, 10Gen, Basho and Twitter.


The full price tickets are £125 but you can play a game on their site for a £10 discount (only before October 1st though, it expires then). You can get more information about this event from the conference's main website.

Gonzalo Ayuso: Combining Zend Framework2 and Symfony2 components with Composer to build PHP projects


In his most recent post Gonzalo Ayuso shows you how to merge Zend Framework 2 and Symfony2 components into the same project using Composer.



Zend Framework 2 is finally stable. I must admit that I'm not a big fan of ZF (or even Symfony2) as a full stack framework. I normally prefer to use micro frameworks, but those two frameworks (ZF2 and SF2) are great as component libraries. Today we are going to build a simple console application (using symfony/console component) to list the database tables (using zendframework/zend-db's Metadata).


He starts with the information you'll need to put into your "composer.json" file to get the needed packages (and set up the autoloader a bit). Included in the post is the code to create his "SchemeCommand" class to make the new CLI command, one that connects to a database and echos out the metadata about the given table. A unit test is also included.

2012年9月7日星期五

Site News: Popular Posts for the Week of 09.07.2012

Popular posts from PHPDeveloper.org for the past week:

Fabien Potencier: Why Symfony?


In this new post to his blog Fabien Potencier offers some of his own supporting reasons for choosing the Symfony framework over some of the other options out there, providing some of the "main selling points" it offers.



I like to think that most popular frameworks are modular enough, fast enough, well-documented enough; they are using well-known design patterns. So, besides the buzzwords, what is unique to Symfony? Why would you want to use Symfony instead of Z? That's the question I'm going to answer in this post.

Included in his list of plusses in Symfony's favor are things like:



  • Symfony is not a framework but a project.
  • Symfony enjoys a huge community of users and contributors.
  • Symfony embraces the "don't reinvent the wheel" philosophy, and provides tight integration with many other Open-Source projects.
  • Symfony tries to bring innovation to PHP



Check out the comments for more reasons from other members of the Symfony community.

2012年9月6日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

Community News: Zend Framework 2.0.0 STABLE Released!


The Zend Framework is proud to announce the first stable release of the long awaited Zend Framework v2 codebase!




The Zend Framework community is pleased to announce the immediate availability of Zend Framework 2.0.0 STABLE! [...] Zend Framework 2 has been years in the making. Version 1.0.0 was released in July 2007 -- over 5 years ago! Since then, we've incrementally added features, building on the solid base we'd created.



[...] It's not perfect. No software project is. But I think it's qualitatively better. We finally achieved a dream that was conceived in the 0.X days of Zend Framework, to be able to create and consume standalone modules of MVC code.




They mention the work of a few different individuals and some of the newer pieces of functionality in this version like the ModuleManager and the dependency injection container, ZendDi. They already have three things posted to help you get started with this latest release: the latest download, a skeleton application and the ability to try out ZF2 on phpcloud.

Lorna Mitchell: Do Open Source with Git and Github


So you've been working on your own code for a while now but have been hearing about Github and how it makes it simple to contribute to other projects too. Maybe you haven't found the time to get into git and Github yet. Well, this new post (a reprinted article from php|architect) to Lorna Mitchell's blog will tell you all you need to know.



Often I find absolutely competent programmers, who aren't involved in open source, either because they don't know how to approach a project, or because they just aren't sure how the process even works. In this article we'll look at one example, the conference feedback site joind.in, and how you can use GitHub to start contributing code to this project. Since so many projects are hosted on github, this will help you get started with other projects, too.


She covers all you'll need to know to get in and get going with Github - forking a current repo (she uses Joind.in as an example), cloning your fork, making updates and submitting them as a pull request back to the main project. There's also some things about general git topics like branching, merging from the upstream source and using "git log" to view the changes.

PHPBuilder.com: Handling Hierarchical Data in MySQL and PHP


On PHPBuilder.com today there's a new tutorial showing you a way to work with hierarchical data in MySQL from your PHP application in two different ways (methods).



The hierarchical data structure is one of the most common data structures in programming. It represents a set of data where each item (except the root) has one parent node and one or more children nodes. Web programmers use hierarchical data for a number of applications, including content management systems, forum threads, mailing lists, and e-commerce product categorization. In this tutorial , I will explain how to manage hierarchical data using MySQL and PHP. Specifically, I will explore the two most popular hierarchical data models: adjacency list model and nested set model.


They start with the adjacency list model, showing how to do a left join on the table on the parent ID to record ID and then filter through them, merging them into a main array as needed. The nested set model is slightly different and involves two new columns, a "lft" and "rgt", that point you to the records around the current one. This method makes the actual SQL query to find the structure a bit simpler, but isn't quite as flexible as the first method.

2012年9月5日星期三

NetTuts.com: Dependency Injection: Huh?


On NetTuts.com today there's a new tutorial introducing dependency injection and how it compares to other injection types (like setter and constructor). It shows how to apply the "Inversion of Control" methodology to create a container that can be reused across the entire application.



Chances are, at some point in your learning, you've come across the term, "dependency injection." If you're still relatively early in your learning, you likely formed a confused expression and skipped over that part. Still, this is an important aspect of writing maintainable (and testable) code. In this article, I'll explain it in as simple a way as I'm capable of.


He starts with an example of setter/constructor injection and talks about how they can make it difficult to use the class as things get more complex. His solution is to create a simple DIC (dependency injection container) that stores instances of objects or closures that can be extracted an reused.

Reddit.com: What do you guys think of Laravel Framework?


In this new post to Reddit, a poster asks for opinions on the Laravel framework:



t seems to be the hot framework this year, straight out of the oven, and into the hands of many bloggers who religiously swear by it. I've been using it for a few weeks and have formed my own opinion on it.


He lists some his own pros (easy to learn, good routing) and cons (still very news, smaller community and support sources) and asks for thoughts from other users of the framework. Comments include things like:



  • One of the downsides to laravel seems to be that it's an extremely fast moving target (in comparison to most other frameworks out there).
  • Lack of contract / freelance work out there for it, and having to use the irc channel for support, where you can be somewhat overlooked if you ask beginner questions.
  • It's a nice enough framework that leaves a bad taste in my mouth due to all the buzzwords used to describe it. Beautiful, artisan, fluid, etc etc. One word I hardly ever hear is utilitarian.
  • My primary need as a developer at this point is stability. I simply can't bother with a package this new and unsupported, even if it is positively fantastic.


There's comments going both ways - some in support of the framework (including one of the authors of it) and some with their criticisms. What do you think of this new framework on the block - share here!

PHPMaster.com: Patterns for Flexible View Handling, Part 2 - Using Decorators


PHPMaster.com has posted the second part in their series looking at design patterns in handling views in your framework of choice. In this new article they focus on the decorator pattern, using additional functionality to augment the results from the view being rendered.



It's also feasible to manipulate views in fairly flexible fashion by appealing to the niceties of a few other patterns as well, including the rather underrated Decorators. If you're wondering in what parallel universe Decorators get along with views, in this part I'll be showing how to put them to work side by side in nice orchestration to bring to life yet another view module.


They create a simple example where an HTML element (based on an interface) is rendered - a span tag - with content passed in on creation. They take this same logic and transfer it over to the View handler, making handlers for difference pieces of the content (outer and inner). These decorators are then passed in the data from the view and rendered in order.

2012年9月4日星期二

Community News: Latest PECL Releases for 09.04.2012

Latest PECL Releases:

Community News: PHPBenelux 2013 Call for Papers Opens


The PHPBenelux conference has officially announced the opening of the Call for Papers for their 2013 event (happening January 25th and 26th):



fter three successful conferences earlier this year and last year, the PHPBenelux team is proud to announce the 4th edition of the PHPBenelux Conference. Like last year, the conference will last two full days, starting with a half day tutorial followed by 1.5 days of conference. The conference is on Friday 25th January and Saturday 26th January 2013 in Antwerp, Belgium. Become part of this year's speaker schedule at the PHPBenelux Conference 2013. Each chosen speaker receives a speaker package!


There's two types of sessions - the 60 minute regular sessions and 3 hour tutorials. Suggested topics include "Content Management Systems", "Frameworks", "Best Practices" and "HTML5". The Call for Papers is only open until October 1st so be sure to submit your ideas today!

Freek Lijten: SOLID - The L is for Liskov Substitution Principle


In this new post to his site Freek Lijten picks back up his series on the SOLID design principles with a look at the "L" in the acronym - the Liskov Substitution Principle.



The Liskov Substitution Principle (LSP) was coined by Barbara Liskov as early as 1987. The principle is very tightly connected to the earlier discussed Open Closed Principle. A good way of adhering to the OCP is understanding and implementing code that uses the Liskov Substitution Principle. In this article we will discover why and how.


He gives a more understandable explanation of what the rule tries to suggest - a standardized interface that each of his "Bike" instances follows to ensure the contract of a consistent API. Then each of the child classes can reliably assume that there are methods they can use because they'll always inherit them.

Wojciech Sznapka: Export colored Behat scenarios to PDF


Wojciech Sznapka has shares his technique for creating colorized exports of Behat tests for use in PDF files:



Behat scenarios are one of the best ways to describe system. UML Use Cases or tons of pages in SRS documents are fine, but hard to understand from the begining, and even harder to maintain in the future. Behat eases this process and also gives opportunity to automate requirements verification. To write Behat scenarios you need a text editor. I've picked my favourite - Vim, which highlights *.feature files syntax. But business people mostly don't use Vim, so I need to figure a way, to expose scenarios in easy and pleasant way.


His solution involves setting up some printing options in vim to export the tests as a Postscript file, setting the "colorscheme" to the default setting so the colors will be retained. The result is exported (via the "hardcopy" command) and can be converted into a PDF (with a result like this).

Programmers Community Blog: 20 controversial programming opinions


On the Programmers Community Blog there's a post (with quite a bit of feedback) that lists twenty controversial opinions about programming and programmers in general that have been proposed over the years.



One of the very first ideas we had for this blog was to convert some of the wonderful gems of the early era of our site, the undisciplined period, to blog posts. Questions that were once enthusiastically received by the community, but no longer fit Programmer's scope.


The post has the top twenty answers to the "What's your most controversial programming opinion?" question as proposed on StackOverflow and includes things like:



  • Programmers who don't code in their spare time for fun will never become as good as those that do.
  • The only "best practice" you should be using all the time is "Use Your Brain".
  • Not all programmers are created equal.
  • If you only know one language, no matter how well you know it, you're not a great programmer.
  • Your job is to put yourself out of work.
  • Readability is the most important aspect of your code.


Check out the full post for the complete list...and for the 100+ comments that have been added to it by programmers with both agreeable and disagreeable opinions.

Dev.Umpirsky.com: Use Poedit to Extract Translations from Twig Templates


In this new post to the Umpirsky.com development blog, they show you how to use poedit to extract translations from Twig templates.



By default, Poedit does not have the ability to parse Twig templates. In Twig documenation there is a simple example which shows how to extract translations. This can work with few modifications, but I wanted to make reusable tool which will allow you to parse Twig templates just like you do with plain PHP templates.


The result is the Twig-Gettext-Extractor that's set up inside Poedit as a parser command for "*.twig" files. This automatically extracts the information so that the editor can read the data from the template.

2012年9月3日星期一

Community News: Latest PEAR Releases for 09.03.2012

Latest PEAR Releases:

Shashikant Jagtap: Behat2.4 : Painless installation with Composer


Shashikant Jagtap has a new post to his site today showing how to painlessly install Behat (2.4) with the help of the Composer package manager.



Behat has becoming so popular in recent days. Behat has drastic changes in recent days in order to add some cool features into it. [...] In this tutorial, we will see how to upgrade Behat vesion with use of composer . Most of us have been installed Behat with 'pear' packages. behat version installed with pear has no longer supported.


He includes the commands to remove the current PEAR install (if it's there) and what you'll need to add to your "composer.json" file to pull in the main Behat package as well as the Geherkin parser and Mink extension. There's also a command you can use to be sure everything's working correctly.

Gonzalo Ayuso: Dependency Injection Containers with PHP. When Pimple is not enough.


Gonzalo Ayuso has a new post talking about dependency injection today and proposes his own DIC solution (dependency injection container) "when Pimple is not enough".



Two months ago I wrote an article about Dependency Injection with PHP and Pimple. After the post I was speaking about it with a group of colleagues and someone threw a question: "What happens if your container grows up? Does Pimple scale well?" The answer is not so easy. Pimple is really simple and good for small projects, but it becomes a little mess when we need to scale.


His solution comes from the Symfony2 framework itself - using its DIC separately from the framework. He includes a configuration example and some simple classes that depend in each other. He also shows how to use imports in the config as well.

PHPMaster.com: The Need for Speed: Profiling with XHProf and XHGui


On PHPMaster.com today Matt Turland has an article posted about using XHProf and XHGui to find the performance issues in your application and profile them to help optimize things.



Profiling is the process of measuring the execution time of each function or method call involved in servicing a single page request. The data collected from this process can reveal issues such as a particular method taking a long time to execute or being called a large number of times. Profiling a PHP script generally requires installing a PHP extension. The two more popular extensions for this purpose are Derick Rethans' Xdebug and Facebook's XHProf. This article will focus on XHProf.


He walks you through the installation of both and shows you some sample results of the profiling of a simple application and how you can compare the results across profiling runs. Additionally, if you install graphviz support, you can generate the call stack output in a visual form to make for easier consumption.