2011年5月31日星期二

Community News: Latest PECL Releases for 05.31.2011

Latest PECL Releases:

Slawek Lukasiewicz's Blog: Zend Framework: Reflection


Slawek Lukasiewicz has a recent post to his blog looking at a tool that comes bundled with PHP that can help you find out more about your own code (or really any other piece of code out there) - the Reflection API. In his post he looks specifically at the functionality the Zend Framework has built on top of the base PHP API.



Zend Framework has own Reflection extension. It is mostly build upon genuine PHP Reflection API and extends existing features. The completely new Zend_Reflection module feature is introspection of docBlock tags.


He includes two code examples using this component of the framework - grabbing the docblock off of a specific method (and even how to grab specific tags from inside it) and how to grab the body content out of a given method, with or without the docblock attached.

Chris Hartjes' Blog: Book Review -- CakePHP 1.3 Application Development Cookbook


Chris Hartjes has posted a new book review to his blog today of the Packt Publishing release the "CakePHP 1.3 Application Development Cookbook". Like many other traditional "cookbook" style books, it provides a set of solutions to common issues CakePHP developers might come across.



personally find the "cookbook" style of books to be the most helpful. They enable me to quickly find answers to the problem "show me how to do something realistic using your tool". Hello World doesn't cut it for the tools I need to use. [...] Like any well-thought-out book, they cover the main components of CakePHP. One of the thing I liked was that you didn't have to necessarily read the book from front-to-back in order to get something from it.


He mentions other positive things about the book - like the chapter on using the command-line tools that come with CakePHP - and one of the negatives (not so much about the book as it is the CakePHP project's choices).

2011年5月30日星期一

Community News: Latest PEAR Releases for 05.30.2011

Latest PEAR Releases:

Script-Tutorials.com: How to Protect any Site from Spam using Akismet


From Script-Tutorials.com there's a new post that wants to help you prevent one of the biggest menaces of the social online world - spam. Their solution uses the Akismet service to detect possible spam and notify you.



What is spam? - this is (usually) any message which not relevant to this page - usually just an advertisement of something (and even with a backward link to another site). Yes, you can put the first line of defense - a captcha, but I think spammers are also ready for this and find ways to avoid the CAPTCHA (or, they even can solve its by self). In today's tutorial I'll show you how to create a second line of defense against spam - using web services - for example akismet.


They include all the code you'll need to create a simple interface to the Akismet system with the help of this library that handles a lot of the connection and messaging for you. They apply it to a comment form and check the POSTed values against the Akismet spam checking. You can download the full package to get started immediately.

Play nice when extending Exception


Lukas Smith has a suggestion for developers out there who get the idea to start messing with the order of the parameters of PHP objects/methods - play nice. His example is specifically with Exceptions.



This is just a short follow up to a recent tweet of mine. I have seen this repeatedly happen, even to top notch and usually very careful developers (*). I am not sure why this mistake happens so frequently, but quite often you see code that changes the parameter order for custom Exception constructors. I guess it's mostly because in these cases the developer wants to pass some magic parameters that contain the message (and potentially also the code).


He recommends that, if you really do need to change something like the order of the parameters, use something like a factory to handle the reorganization for you.

Michael Nitschinger's Blog: Caching responses in Lithium


Michael Nitschinger has put together a guide to caching responses in the Lithium framework - a simple update that means your application dosen't even need to reach the controllers to do its job.



I've hacked together a small example on how to easily cache full responses in Lithium. If you need to cache full Response objects in Lithium (which means that your controllers don't even get called when there's a cache hit), you can place this in your app/config/bootstrap/cache.php file (note that this is certainly not "production ready", but it should give you a starting point).


The code adds a new filter to run on execute that takes the current object (the Response object hit the first time) and use the Cache functionality to push it into storage. Their cache key is based on the URL, so each requests is cached individually. You can find out more about filters and the framework at Lithify.me.

2011年5月27日星期五

Site News: Popular Posts for the Week of 05.27.2011

Popular posts from PHPDeveloper.org for the past week:

Box UK: Unboxing: Silex


On the Box UK site there's a recent post where they "unbox" Silex the recent micro-framework release from Fabien Potencier and the Symfony community. They test things out by creating a sample application, a simple feedback form.



"Silex is a PHP micro-framework for PHP 5.3. It is built on the shoulders of Symfony2 and Pimple and also inspired by sinatra." - description from the Silex website. It allows you to pick and choose what components of Symfony2 you want to use. [...] Like Ruby's Sinatra, it provides a way to get web apps up and running with minimal effort and very little boilerplate code.


He talks about the "installation" process (downloading the phar and dropping it into a directory) and includes code snippets of the parts of his application - the basic routing, twig templates and a POST handler for the form submission.

Elated.com: Object-Oriented PHP: Working with Inheritance


On Elated.com there's a new introduction to working with inheritance in PHP for object-oriented applications. They work through some of the basic concepts including parent/child classes, final and abstract classes and interfaces.



In this article we're going to explore the idea of inheritance in object-oriented programming, and how inheritance works in PHP. With inheritance, your objects and classes can become much more powerful and flexible, and you can save a lot of time and effort with your coding.


They start with the basics of how inheritance works and then move right into creating child classes from a parent. Their example code makes a basic forum system (just example code, not fully functioning) with administrators, members and forum creation. They use this as a base to show the method overriding and exposure with "final". The finish it off with examples of two things that can promote good application structure - abstract classes an interfaces.

2011年5月26日星期四

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

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

Michelangelo van Dam's Blog: Book Review: PHP Development in the Cloud


Michelangelo van Dam has posted a book review of one of the latest offerings from the php|architect presses, Ivo Jansch and Vito Chin's "PHP Development in the Cloud".



A couple of weeks ago, my dear friend Cal Evans asked me to review the book "PHP Development in the Cloud" written by "Ivo Jansch" and "Vito Chin". I accepted as I was very interesting in exploring more of the cloudy world I just found myself in the middle of. Another reason was that both authors were fellow co-workers at Ibuildings back in the day. I promised this would be an objective review seen through the eyes of a developer just started exploring the mystifying world of cloud solutions.


He briefly covers the focus of the book and how it makes the distinctions between platform types (PaaS, Sass, etc) to help clear a few things up. He liked that the book was written and organized well, but noted that some of the examples provided were hard to get working on the different platforms. He wished there was some sort of disclaimer that came with it that there'd be a learning curve on the examples that might require some additional work outside of the example to get started.

Zend Developer Zone: Announcing the May 2011 Zend Framework Bug-Hunt


This new post on the Zend Developer Zone (from Ralph Schindler) is announcing this month's Zend Framework Bug Hunt Days starting today (the 26th) and running through Saturday (the 28th).



For those who haven't put the reoccurring event in their calendar, this announcement is for you: Zend Framework Monthly Bug-hunt is here again! Tomorrow, Friday and Saturday of May (the 26th, 27th and 28th 2011), we'll be hosting our monthly bug hunt. For those of you unfamiliar with the event, each month, we organize the community to help reduce the number of open issues reported against the framework.


He mentions last month's winner, Adam Lundrigan, and some hints on how to get started (including a few screenshots on helping you find issues to work on). See the rest of the post for complete information.

2011年5月25日星期三

Community News: Latest Releases from PHPClasses.org

PHPBuilder.com: Tracking User Activity in PHP with Cookies and Sessions

On PHPBuilder.com today there's a new tutorial from Leidago Noabeb showing how you can track your website's users with the help of sessions and cookies, the handling for which are already included in PHP.



So, why can't you maintain state with HTTP? The main reason is because HTTP is a stateless protocol, meaning that it has no built-in way of maintaining state between transactions. For example, when a user requests one page followed by another, HTTP does not provide a way for us to tell which user made the second request. In this article we will look at what maintaining state in PHP applications entails.


They introduce cookies and how they can be used to store information about the user's session on their client for a certain amount of time. This makes it much simpler for the cross-page or cross-session details to persist. There's a bit of code showing how to set and get a cookie and how to do the same with a session.

IBM developerWorks: Starting to use ODBC with PHP


On IBM's developerWorks site there's a new tutorial that wants to help you get started with ODBC in PHP, using the iodbc libraries and extension for PHP to connect to a database and pull back results.



Let's look at how a typical Linux-Apache-PHP-MySQL (LAMP) environment can be transformed into this flexible Linux-Apache-PHP-ODBC (LAPO) environment. There are two general options for ODBC drivers on Linux®: iODBC and unixODBC. Both sets of drivers have their own pros and cons, and both work with PHP, but they work with different sets of databases. My choice is iODBC because of its traditionally strong connection to web programming languages like PHP and Ruby, as well as its stability in working with ODBC-friendly databases like MySQL and OpenLink Virtuoso.


There's a few steps in there to help you get the needed tools installed (linux server) to make the connection. Snippets of code are included showing how to connect to the server, run some simple SQL statements, fetch returned row information and do some basic debugging of the connection.

2011年5月24日星期二

Community News: Latest PECL Releases for 05.24.2011

Latest PECL Releases:

Web Species Blog: The New Era of PHP Frameworks


On the Web Species blog there's a new post from Juozas Kaziukenas about the new era of PHP frameworks that are coming out (or might be already here). This new group of frameworks is redefining the PHP framework world:



I have worked on a lot of different systems and projects in my years and most of that was spent doing PHP. However just recently I have noticed a new major point in time - a new era of PHP frameworks. Seems like everything is changing these days. I want to discuss what I think the current state is, what's wrong with it and how the new gang of frameworks is going to change it.


Juozas starts with a brief history of the "why" and "how" PHP frameworks came to be and how they've improved over time. In this new generation things like dependency injection containers and annotations are changes for the better. Three frameworks mentioned specifically as driving forces in this new movement are Zend Framework 2.0, Lithium and Symfony2.

Slawek Lukasiewicz's Blog: Zend Framework: logging with Firebug and FirePHP


Slawek Lukasiewicz has a new post to his blog today showing you how to use the popular Firebug extension for Firefox with the FirePHP plugin to make error logging simpler and less obtrusive without ever having to leave the browser.



If you use Firefox, I bet you already know Firebug extension. This is irreplaceable tool for web development. But there is also FirePHP extension, which provides possibility to log into Firebug console from PHP scripts. This is very convenient way for debugging process, because logs are independent from application output.


He shows the integration you can do with the Zend Framework's Zend_Log component to write basic messages and the Zend_Wildfire component to write tabular data back to your browser's console with two snippets of code.

Laura Thompson's Blog: All systems suck


Laura Thompson has a quick post to her blog explaining one simple fact that all developers (or really anyone even loosely related to computing systems) should remember - all systems suck.



I've been thinking a lot about this idea lately. I've spent a lot of years as an engineer and consultant fixing other people's systems that suck, writing my own systems that suck, and working on legacy systems, that, well, suck. Don't let anyone fool you. All systems suck, to a greater or lesser extent


She presents her "slightly jaded" points of view about legacy systems, current systems and ones yet to be built nothing that, no matter how impressive and well-planned out they are, they'll still suck (some maybe just a bit less than others).



Here's the punchline: sucking is like scaling. You just have to keep on top of it, keep fixing and refactoring and improving and rewriting as you go. Sometimes you can manage the suck in a linear fashion with bug fixes and refactoring, and sometimes you need a phase change where you re-do parts or all of the system to recover from suckiness.

2011年5月23日星期一

Jani Hartikainen's Blog: You don't need a service layer: Fat controllers are okay


Jani Hartikainen has a new post to his blog today about why, in your framework-based applications, it's okay to have "fat controllers" instead of a service layer.



Here's a counterpoint to the currently popular view of "fat controllers are bad", and the current fad of everyone and their cousin implementing service layers: You don't need one. Fat controllers are okay too.


He starts by explaining the "why you don't need a service layer" part, mentioning that keeping it in the controller keeps things simple and keeps your code from having to go through extra hoops just to work correctly. He also points out that, just because he recommends "fat controllers" doesn't mean he's advocating code reuse. In fact, just the opposite:



It's fine if you code your things in the controllers, but there comes a point when you should stop that. The moment you realize you're duplicating your code, stop and refactor. This is one of the very basics of software engineering: Avoid duplication by creating functions and classes.

Till Klampaeckel's Blog: Yahoo: oauth_problem=consumer_key_rejected


During some of his work with the Yahoo! Search Boss API, Till Klampaeckel came across an issue with the OAuth connection causing an error of "oauth_problem=consumer_key_rejected" with his Zend Framework-based application.



The above process doesn't even take five minutes, but then I spent eight hours figuring out what oauth_problem=consumer_key_rejected means. Spent a couple hours googling, reading bug reports and even posted to the Yahoo! group associated with Search Boss. To cut to the chase: When you create a new project, it's not sufficient to just activate "Yahoo! Search Boss" (and provide billing details and so on).


His real issue was because of how Yahoo! apparently creates (or when they create) the OAuth connection information for you. He gives a two line example of how the Zend Framework can grab a OAuth token with Zend_Oauth. He goes on to talk about the OAuth implementation in PHP and how it's "pretty sucky" and that there's not much documentation around to help. He got things working, though, and included the sample code he used to make the connection - pulling the info from a an oauth.ini file, pushing the authentication parameters to the remote side, grabbing the headers and making the HTTP request with the OAuth information in place.

Zend Developer Zone: The HackForGood Evenings - San Francisco


On the Zend Developer Zone David Coallier has a post about an effort starting up in San Francisco called the HackForGood Evening where developers come together to work on software with the sole purpose of helping make the lives of other people better (those who can't do for themselves).



Starting from there we realised that the idea and purpose of writing software to help the lives of the people around us was exactly what we are about but more importantly, this was an idea that should happen more than once. The HackForGood evenings were born. The following day, we decided to put a simple descriptive page together and organised the event on Eventbrite. Once this was in place we plainly announced it on Twitter to see who would be interested. After having received over 30 signups in 2 hours, we knew that we had hit a nerve and decided to make this event a success.


He goes on to talk about the evening - the presentation of the sponsors, the split off of the groups and the work (hours of it) that was done to create things like the winning entry - 911Stealth, a mobile app for contacting local emergency services when you are unable to use your voice.

2011年5月20日星期五

Site News: Popular Posts for the Week of 05.20.2011

Popular posts from PHPDeveloper.org for the past week:

Lorna Mitchell's Blog: PHP OAuth Provider: Request Tokens


In the next of her series looking at OAuth in PHP, Lorna Mitchell has posted a look at request tokens and how to hand them out via your application.



The consumer requests a request token (see my earlier post about consuming OAuth), and as a provider, we need to handle that request. In my example, I chose to pass the variables as GET parameters, but you could adapt this to handle POST variables or information contained in HTTP headers.


She includes the code (using the functionality of the pecl_oauth extension) to provide a token and the three functions you'll need to define to get things working - the consumerHandler, the tokenHandler and timestampNonceHandler. She also includes a sample database table structure for storing the OAuth information for a user.

Josh Adell's Blog: Logging User Sessions Across Requests


Josh Adell has a new post to the Everyman Software blog talking about a solution he and his team have developed for logging user sessions across requests with the help of the Zend_Log component and a custom logging formatter.



One way to handle this is to put a request-specific identifier in every log message. But I shouldn't have to remember to append or prepend the identifier to their log messages. I'd rather have it happen automatically, without me or my teammates having to think about it. Here's a method we've been using to try and untangle the mess and retain the usefulness of our logs. The code uses Zend's logging component, but can easily be adapted to other log systems.


Their example sets a custom log format message with placeholders for a timestamp, log ID number and the log message. A unique ID is then generated for the user's session and applied to the Zend_Log object. This data is then automatically applied to the log file's output without any extra hassle. The full sample code (pretty simple, really) is included.

2011年5月19日星期四

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

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

Ralph Schindler's Blog: Learning About Dependency Injection and PHP


Ralph Schindler has a new post to his blog describing some of the what he's done to understand dependency injection in PHP and includes some illustrations to share that information.



Whatever the reason, one of the newest concepts (at least over the past 3 years or so) that has emerged as one of our heated topics of debate is how to manage object dependencies. Interestingly, the argument of how to manage dependencies is generally named by the solution which it's proponents give as the solution: dependency injection (the abstract principle is actually called Inversion of control).


He starts with simple examples - pushing an object into the creation of another - and backfills with a brief history of dependencies in PHP applications for a little context. He talks about DI frameworks like Spring and some of the other criticisms and thoughts you'll need to consider when using DI (and DI containers) during development and deployment.

Johannes Schluter's Blog: Escaping from the statement mess


In a new post to his blog Johannes Schluter suggests an alternative to using prepared statements in PHP applications using a database - creating a handler method that allows for dynamic queries as well as proper escaping of values.



Now prepared statements were a nice invention some 30 years ago abut they weren't meant for making things secure and so they do have some shortcomings: One issue is that preparing and executing a query adds a round-trip to the server where it then requires resources. [...] With prepared statements you first have to build the list of place holders (the exact amount of place holders (?) separated by a comma, without trailing comma) and then bind the values and mind the offsets when having other values - this typically becomes ugly code.


He includes the code for his alternative, a function using the mysqli extension to let you create dynamic SQL that still uses placeholders and proper escaping to prevent both SQL injection issues and resources problems caused by the multiple hops back to the database.

Web Developer Juice: PHP Magic Functions: Best Part of Object Oriented PHP - Part 2


Web Developer Juice has posted the second part of their series looking at some of the "magic functions" that PHP has to offer - special functions that do automagic things in your scripts and classes. Part one can be found here.



In my previous post ( PHP Magic Functions ), I discussed about __construct, __destruct, __call and __callStatic. Lets explore a few more magic functions...

In this latest part of the series they look at three functions:



  • __set/__get
  • __invoke

2011年5月18日星期三

Community News: Latest Releases from PHPClasses.org

PHPBuilder.com: Implementing User Authentication and Session Management with PHP


On PHPBuilder.com there's a new tutorial posted showing you how to create a user authentication system that uses sessions to handle the logged in user's information.



Outside of installation and configuration issues, reader questions pertaining to user authentication and session management almost certainly rank among the most common I receive on an ongoing basis. The logic itself is pretty straightforward; however, even a simple implementation involves a number of small but important details which aren't always so easy to figure out the first time around. This tutorial serves to dispel much of the confusion by guiding you through the implementation of a simple user authentication feature which will subsequently keep the user logged in via a session.


He helps you create the simple login form, a table in MySQL to store the user data in and the PHP script (complete with input filtering) to handle the login. The system also tracks the last login of each user by updating the table with a timestamp each time they successfully log in.

Rafael Dohms' Blog: Debugging PHPUnit Tests in NetBeans with XDebug


Rafael Dohms has, in a recent post to his blog, shown how to set up NetBeans to use PHPUnit tests with XDebug. This allows him to run his unit test and track down problems with the handy XDebug extension right from his IDE.



Every now and then you run into this weird situation in your code, where something that was supposed to zig is now zagging and it makes no sense whatsoever. For me this ends up happening in my unit tests since i'm not running everything in the browser everytime and since my tests usually run more scenarios then a regular browser run, that's where the weird stuff happens.


He shows you how to configure NetBeans with the path to your local PHP installation, configure the xdebug settings in your php.ini and how to coordinate the PHPUnit install to send its output to your NetBeans instance. Then it's as simple as clicking "Debug" on the project and running "phpunit-debug" from the command line.

Zend Developer Zone: Design Patterns I Hate


On the Zend Developer Zone today there's a new post from Keith Casey about some of the design patterns he hates - ones that are misused too often and have become more of a "worst practice" at times than others.



To be clear, I think Design Patterns have their place. When used properly, they can make our lives easier and our code better. When they're misused - "If the only tool you have is a hammer.." - then they can become the bane of our existence. Unfortunately, some Design Patterns seem more susceptible to this than others. So maybe this is less "design patterns I hate" and more of "design patterns that have been abused beyond all sense of reason"... I'll let you decide.


He has three of the most commonly misused design patterns in his list. Anyone who has looked into using patterns in their applications will recognize them:



  • Active Record
  • Factory
  • Singleton


For each, he describes some of the bad implementations he's seen and notes that, while these are commonly abused, they can still be redeemed by being used appropriately.

2011年5月17日星期二

Community News: Latest PECL Releases for 05.17.2011

Latest PECL Releases:

Script-Tutorials.com: Phar - PHP archiving practice


On Script-Tutorials.com today there's a new tutorial showing you how to use one of the more under-used and powerful features of recent PHP releases - the phar packaging for creating self-contained archives.



I guess you noticed that due your project become larger - the more and more files it contain. Sometimes it comes to the thousands of files. And then - Phar can help you. This utility allows us to pack a variety of files in the single library file. Thus, we can significantly reduce the number of include files in the project, and work with the entire library as with single file. It is also possible to have a packed (gzip/bzip2) version of the library.


They show you how to create simple phar archive (sample code here) that contains a few classes linked by an index.php file.

Test.ical.ly Blog: phpDay Summaries - Days 1, 2 and 3 (Summary)


On the test.ical.ly blog there's a series of posts with Christian's "live blogging" from the phpDay event that just wrapped up in Verona, Italy:



In the first post he talks about the workshops for the first day from Sebastian Bergmann, Fabien Potencier or Paul Borgermans. He ended up attending Fabien's workshop and a talk on document conversion from Kore Nordmann and Tobias Schlitt.



In parts two and three he mentions other sessions he attended with topics ranging from Hadoop, Varnish, Git and testable code.



He wraps it all up with a summary post about the "five days of conferencing [that] have passed in what felt like only a few hours".

2011年5月16日星期一

Community News: Latest PEAR Releases for 05.16.2011

Latest PEAR Releases:

XPertDeveloper.com: Is Your PHP Application Affected by the Y2K38?


On the XpertDeveloper.com site there's a new post reminding you of an date could cause all sorts of problems with your PHP application - the effects of the Y2K38 bug.



Y2K38, or the Unix Millennium Bug, affects PHP and many other languages and systems which use a signed 32-bit integer to signify dates as the number of seconds since 00:00:00 UTC on 1 January 1970. The furthest date which can be stored is 03:14:07 UTC on 19 January 2038. Beyond that, the left-most bit is set and the integer becomes a negative decimal number or a time prior to the epoch.


If you're worried about your application's support for date and time handling, there's a pretty simple fix - replace your current handling with the DateTime functionality. This handles them correctly.

2011年5月12日星期四

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

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

NetTuts.com: How to Work with PHP and FTP


On NetTuts.com there's a new article stepping you through what you'll need to know about using FTP in PHP, including a basic useful and expandable class.



It's always important to first outline exactly what functionality your class should include. In our case: connecting to a server, create a folder on the server, upload a file, change directory, retrieving the directory listing and downloading a file.


They first look at what FTP is and then how to set up the class that includes some simple logging, connection handling and how to call the class with a username, password and hostname. The class lets you create a remote directory, upload a file, view a list of remote files and downloading a selected file. Full source for the class is available as a download.

Chris Jones' Blog: PHP 5.4 is Gathering Momentum


In a new post to his blog Chris Jones talks about the "gathering momentum" that's forming around the push to the next PHP release, PHP 5.4, including discussions on mailing lists and IRC.



Discussion on the PHP mail lists and IRC channels in the past few days has been looking positive about an alpha release of PHP 5.4 soon. This will be taken from the "trunk" branch of PHP. The exact feature list is under discussion but the mood seems to be "ship what we currently have" though a couple of features are slated to be deferred until later.


He specifically mentions this mailing list post and the emphasis he puts on testing the code. If you'd like to get involved, you can subscribe to the mailing lists here.

2011年5月11日星期三

Matthew Weier O'Phinney's Blog: Backported ZF2 Autoloaders


In a new post Matthew Weier O'Phinney talks about autoloaders in the Zend Framework and the changes they've made from ZF1 to ZF2. He also includes a link to a package you can try out if you'd like to backport the ZF2 autoloaders to your ZF1 application.



Interestingly, I've had quite some number of folks ask if they can use the new autoloaders in their Zend Framework 1 development. The short answer is "yes," assuming you're running PHP 5.3 already. If not, however, until today, the answer has been "no."
I've recently backported the ZF2 autoloaders to PHP 5.2, and posted them on GitHub [tarball here].


His autoloader backport scripts include a class map generation tool, a PSR-0 compliant autoloader, a class map autoloader and an autoloader factory for loading multple strategies at once. He also includes a sample of how to use it with a bit of the output it might give you for your project.

Keith Casey's Blog: php|tek 2011 Hackathon


Keith Casey has a new post to his blog today talking about an event happening at this year's php|tek conference, a hackathon in the after-hours of the second conference day (the 26th for those keeping track).



So I'm proud to say that at php|tek this year, we've managed to gather a bunch of these people to come to show what they're building at our third annual Hackathon. On Thursday night (May 26th), we'll have over a dozen projects represented by some of the best and brightest out there. Even better, since it's a Hackathon, you can't just passively watch and listen. We expect you to show up and try out some code and generally get your hands dirty.


There'll be several projects there for attendees to choose from including web2project, Joind.in, Spaz, Frapi, the Zend Framework and even a PHP testfest for helping test the PHP language itself. For more info on these and the full list of other projects that'll be there, check out this page on the php|tek conference site.

Community News: Latest Releases from PHPClasses.org

DZone.com: PHP UML generation from a live object graph


On the PHP On Windows section of the DZone.com site Giorgio Sironi has a new post looking at the process (and script he's created) to create a UML diagram with PHP from a project's current class structure.



Sometimes you need to share a design with your colleagues. You can walk him through the code, and explain which classes and interfaces you created, but there are higher abstracted models that you can show to him to make him grasp the picture quickly. One of these tools is UML, and in particular class diagrams.


His script creates a UML diagram from a PHP object graph, a sort of "reverse engineering" of the current object's hierarchy and relationships. It creates definitions that Yuml.me can use to generate the image and does some handy things like following the path down N levels until it hits "the bottom" and the ability to ignore certain namespaces (like "Zend_" or "Doctrine_") to help limit things down to just your application. He includes a sample set of tests to show it in action as well as a resulting UML diagram generated from the PHPUnit structure.

2011年5月10日星期二

Community News: Latest PECL Releases for 05.10.2011

Latest PECL Releases:

DZone.com: How to send emails from PHP on Windows


On the PHP on Windows site (a part of DZone.com) Svetoslav Marinov has a quick new post looking at how you can set up your Windows PHP installation to be able to send emails similar to its linux cousins.



You'll need a server that you can use SMTP on to send the emails to, but outside of that, the setup is pretty painless. He recommends using the sendmail for Windows tool to do the backend lifting. He includes the settings, both for sendmail and PHP, and configuration changes you'll need to get it all working too.



He points to the mail manual page to grab a simple result for testing the install.

Lars Strojny's Blog: Dependency Injection Container Refactorings, Part Two


Lars Strojny has posted the second part of his look at dependency injection and the refactoring it makes possible. If you'd like to start from the beginning, you can read about part one here.



He breaks it up into two sections (really three, but he advises to ignore the third):


    Introducing a parameter in to the dependency injection container's configuration
  • Setting it up to allow for checks against the environment (development, production, etc)



Code samples and example XML configurations are included for both points to help make them clearer.

Lorna Mitchell's Blog: PHP OAuth Provider: Initial Requirements


Lorna Mitchell has a quick post related to some of the OAuth work she's done on both sides, consumer and provider. This latest post relates to the OAuth pages and endpoints that are needed as a part of the authentication process.



This article uses the pecl_oauth extension and builds on Rasmus' OAuth Provider post. [...] OAuth has a little more baggage with it than just passing a username and password to an API.


She lists the five things you'll need for your service and talks a bit about the registration process and how the consumer key/consumer secret keys are generated. There's no strict definition on them, so her example uses a combination of sha1, mt_rand and substr to get the job done. She also includes a sample "consumers" table for your reference.

2011年5月9日星期一

Community News: Latest PEAR Releases for 05.09.2011

Latest PEAR Releases:

Jani Hartikainen's Blog: How to use built-in SPL exception classes for better error handling


On his blog today Jani Hartikainen looks at how you can use the SPL exception types to allow for better overall error handling in your application. Things like BadMethodCallException and OutOfBoundsException make the errors much more descriptive.



Since PHP 5, there has been a bundle of built-in exceptions - the "SPL exceptions" - in PHP. However, the documentation for these classes is quite lacking in examples, and it can be difficult to understand when you should be using them. The short answer is always.

The list of exception types he recommends include:



  • BadMethodCallException
  • DomainException
  • LengthException
  • OutOfRangeException
  • UnexpectedValueException


For each he gives an example usage of it, sometimes including a bit of code to illustrate.

Liip Blog: Silex - A Grand Micro Framework for PHP


In a new post to the Liip blog Benoît Pointet talks about his experience with Silex, the micro-framework from Fabien Potencier and the Symfony crowd.



In a recent project, my team needed a micro backend for a small educational simulation game which was mostly client-side code. [...] There were so little backend tasks involved that the primary discussion lead to a 'no framework' approach. But after a great presentation by Igor Wiedler at Liip Zurich, we decided to use the Silex PHP micro-framework for our minimal backend needs.


His application ended up being 200 lines of code (with commenting and space) and made use of Doctrine and templating extensions for the framework.



It was fun, fast and allowed us to concentrate on the real challenges of the project.


For more information on Silex, see silex-project.org.

2011年5月6日星期五

Site News: Popular Posts for the Week of 05.06.2011

Popular posts from PHPDeveloper.org for the past week:

PHPRiot.com: Translating Text Using the Google Translate API and PHP, JSON and cURL


On PHPRiot.com there's a new tutorial showing you how to use the Google Translate service to translate the text of your website into any language they support. They interface with it using a cURL connection and JSON messaging.



Google Translate is a service from Google that you can use to translate text or HTML from one language to another. One of the great features of this service is that they now offer an API to let you programmatically translate text. In this article I will show you how to interact with the Google Translate API. Initially, the Google Translate API was available only via JavaScript. This has now changed, as version 2 offers a REST interface which returns translations in JSON format.


They talk about the input parameters you can give the service, the enforcement of query limits and how to handle the results that are returned. The response message is, by default, in JSON so a simple call to json_decode should be all that's needed. They've also included a sample class you can drop in and use for your translation needs (as well as sample usage code).

Symfony Blog: Symfony2: Getting easier (Parts 2 & 3)


Continuing on from his first Symfony2 is getting easier post, Fabien Potencier has two new posts in the series looking at other aspects of the framework that have improved to make developers' lives easier.



In part 2 he talks about a patch that's been applied to help with errors in the autoloading process and throw an exception if something's' not found.



Part 3 talks about an update to help make the pathing shorter on the Doctrine configuration files and the ability to move it to a centralized mapping file in the app/config.

2011年5月5日星期四

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

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

Ryan Mauger's Blog: Using Twig with Zend Framework


Ryan Mauger has written up a new post about an integration he's done using the Twig templating engine (from be Symfony community) with his Zend Framework application to make view handling simpler.



Mostly I thought [what Twig offered] were silly things that were not really needed unless you had a team of designers to work with, however, during my exploration, a couple of things occurred to me that I had not considered about templating systems before. One being the enforced separation of concerns they provide; you simply cannot do anything from inside them which you shouldn't be, keeping your presentation very very clean. The second, being that they're not all as terrible as Smarty.


He helps you get Twig installed (via PEAR chnnel) and includes the code for an application resource and the changes you'll need to make to your application.ini to get things working. He uses a base controller setup, so he shows how to introduce a "twig()" method into that to help with rendering. Finally, there's a sample class included that includes two actions, both using this "twig()" method to pas the output data through the twig interpreter and out to the view.

Voices of the ElePHPant: Interview with Shaun Farley


The Voices of the ElePHPant podcast has posted their latest interview with a member of the PHP community. This time it's Shaun Farley, an organizer of the DC PHP User Group



Cal's "three questions" for Shaun about his website BreweryDb.com and its API:



  • Can you explain what a open data/closed source model model is and why you chose it for BreweryDb?
  • How do users know that BreweryDb won't change their data usage agreement on the API (and what problems it could cause on a wider scale, outside of BreweryDb)?
  • What is the most interesting thing you learned while building an open API?


As always, you can listen to this latest episode either by using the in-page player, by downloading the mp3 or by subscribing to their feed.

DevShed: 7 PHP Frameworks Tested For Speed - Benchmarking PHP Frameworks


In this new post from DevShed today they look at seven different frameworks and compare the speed of how they render a simple request - CakePHP, CodeIgniter, Symfony2, Yii, RainFramework, Doophp and Kohana.



There are so many PHP frameworks that it can be hard to keep track of them all. Some are already very popular, while others are relatively new and unknown. [...] Of the seven criteria [of a good framework], this article will examine only the speed and performance.


They define their structure for testing - hardware and software - as well as some basic settings like number of connections, disabling of caching and these sample files for each of the frameworks. You'll have a see the rest of the post for their results, though.

2011年5月4日星期三

Community News: Latest Releases from PHPClasses.org

James Cohen's Blog: Working with Date and Time in PHP


James Cohen has a new post to his blog today looking at some of the built-in functionality that PHP has to work with dates and times including simple things like strtotime and the DateTime feature.



A lot of people ask questions relating to date and time in PHP. Here are some answers to the most commonly asked questions and common mistakes.


He covers the differences between working with dates in strtotime, worrying about timezone settings and compares the strtotime/DateTime methods for formatting and returning dates, modifying dates, converting between timezones as well as finding the difference between two timezones.

Script-Tutorials.com: Creating a Modern Looking Animated Login System in PHP


New from the Script-Tutorials.com site there's a guide to getting a modern looking animated login system working on your PHP application. It uses jQuery to do some of the "modern" bits when the user logs in.



Today we will continue PHP lessons, and our article will about creating modern php login system. Possible you already saw similar ways to display login forms, and today we will repeat this by self. In result - it will some small element in your page layout, and after clicking on it - will appear some area, where we will see some welcome message, login form and another useful information. All very user friendly. So, its time to try demo.


You can start with the live demo or grabbing the code in a package to investigate or you can follow along in the post - full code and styling are provided.

2011年5月3日星期二

Community News: Latest PECL Releases for 05.03.2011

Latest PECL Releases:

Gonzalo Ayuso's Blog: Performance analysis of Stored Procedures with PDO and PHP


Gonzalo Ayuso has posted the results of some testing he's done in using stored procedures in a PHP application. He compares the run time of two different scripts, one using prepared statements and one without, to see which would perform better in the long run.



Last week I had an interesting conversation on twitter about the usage of stored procedures in databases. Someone told stored procedure are evil. I'm not agree with that. Stored procedures are a great place to store business logic. In this post I'm going to test the performance of a small piece of code using stored procedures and using only PHP code.


In the end, the results showed that the stored procedures method was actually faster and used a bit less memory than the normal "plain PHP" method. It can be a bit more difficult to use than just a SQL statement in a string (properly escaped, of course) but can be worth the extra hassle when you need that performance boost.

Chris Hartjes' Blog: Testing Web Services in Zend Framework 1.x


In a new post to his blog Chris Hartjes shares a technique he figured out for testing web services in Zend Framework 1.x - in his case, a remote application he wanted to mock out with test doubles that would give different responses based on the parameters given.



Reading the existing PHPUnit documentation did not provide me with enough hints on how to solve this particular problem, so while I dug around duckduckgoing for a solution I asked Twitter for help. One blog post and 3 tweets later, I had the underpinnings for my test. Check it out. A walk-through is probably required in order to explain what I did.


The sample test (code included in the post) sets up a mock object to abstract the service connection, loads in some fixture data for the different responses (based on request) and an "expectation object" for the GET request on the mock object. This object and the data is then passed to a handler that responds with the right dataset. The example code is here on github in two methods - testGetTracks and setMultipleMatching.

2011年5月2日星期一

Community News: Latest PEAR Releases for 05.02.2011

Latest PEAR Releases:

PHPClasses.org: Lately in PHP podcast episode 11 - Is the Cloud the Right Solution?


New from the PHPClasses.org site is their latest episode of the "Lately In PHP" podcast - Is Cloud the Right Solution to Host PHP Sites?"



Given the latest problems that occurred in sites that are based on cloud hosting services, Manuel Lemos and Ernani Joppert discuss if the current breed of cloud services are the right solution to host PHP sites. They also comment on the JavaScript Professionals Directory and the JavaScript jobs board which were recently launched to address the increasing demand of developers from companies that have JavaScript job openings.


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

PHPBuilder.com: PHP Dependency Injection Creates More Maintainable Code


On PHPBuilder.com Jason Gilmore has posted a new article looking at the benefits of dependency injection in helping you keep your code more maintainable and well-structured.



Of course, the advantages of object-orientation can only be fully exploited when implemented in conjunction with best practices such as encapsulation and inheritance. One such "implementational" best practice is dependency injection, a design pattern that facilitates the decoupling of otherwise dependent components. [...] Save yourself the trouble and decouple components using dependency injection.


He gives an example of how a simple dependency injection (DI) method on an "Account" class to take the database connection dependency out of the actual class and into an encapsulated object. This way, any sort of standardized database object can be passed in and acted upon. He also mentions two dependency injection containers you could use to help you implement it - Symfony's and Pimple.

Christian Weiske's Blog: Visualizing PHPUnit runs


During some of his development, Christian Weiske found the tests for a project he was working on too slow for comfort and figured there had to be a way to find the root cause:



Running the specific test cases for the part of the application you're working on is easy and fast, but that does not tell you when changes in part A of the app break part B - which happened several times, and all just because I didn't want to wait 45 seconds again and again. So a solution was badly needed; tests should be as fast as possible; preferably < 10 seconds. Before being able to make the slow tests faster, I had to find out which of the 80 tests were slow.


Tools like Jenkinks give more detail on test runs, but a normal PHPUnit install won't. So, he came up with a method that uses Phing's phpunitreport task to generate extra reporting easily. Here's some example screenshots: test results summary, test detail and single page views of the same sort of data.