2012年2月29日星期三
Lorna Mitchell's Blog: Using iterator_to_array() in PHP
Lorna Mitchell has a new post to her blog today showing off a lesser-known but very useful function included in PHP - the iterator_to_array function, used to translate things that implement Traversable into arrays.
Someone watching over my shoulder recently had never seen the ubiquitously-useful iterator_to_array() before. [...] Mostly I find this useful when I'm working with collections of data as these often present themselves as an object that you can foreach() over, but you can't dump it directly. If the object in question implements the Traversable interface, you can instead pass it into iterator_to_array to get the data as an array.
She includes a brief snippet of code showing it in use - transforming the results from a MongoDB cursor object back into an array.
Rob Allen's Blog: An introduction to ZendDi
Rob Allen, Zend Framework guru extraordinaire, has posted an introduction to the Dependency Injection container that's a part of Zend Framework 2 - ZendDi.
Zend Framework 2 provides its own dependency injection container, ZendDi which is a key underpinning of the entire framework and especially the MVC system. I have covered before, my thoughts on the reasons for using dependency injection, so this article looks at the fundamentals of using ZendDi.
He includes some sample code showing a current setup involving constructor injection and how it can be refactored to use the new DI container. With the new version, the resource is assigned to the container and that is referenced when a new object type needs to be created. He also briefly touches on setter injections, noting that he prefers them more for optional dependencies and shows how to enable their use in the container as well.
2012年2月28日星期二
Stuart Herbert's Blog: Setting Up Sublime Text 2 For PHP Development
Stuart Herbert, a big fan of the Sublime Text 2 editor, has put together a post showing you what he thinks is an effected way to set up the editor for PHP development.
As the interest seems to be there, I thought it would be a great idea to follow up with a post taking you step by step through how I've set up Sublime Text 2 for PHP development, and showing you some of the useful features that you get out of the box with Sublime Text 2.
He's come up with some screencasts of his setup so you can see the useful features in action. He points out a few things to install or that use can use to make your development simpler:
- Package Control
- the Soda theme
- how to edit user preferences
- using the "Goto Anything" bar
- using the PHP snippets plugin
- DocBlockr for documentation blocks
- Sublime linter
- Goto Documentation
...and much more. This flexible editor makes it easy to customize just about everything in your environment and with more and more plugins/packages popping up all the time, there's a good chance the feature you need will be introduced soon.
Community News: Pro PHP NYC User Group Forming
In this new post to his blog Kenny Katzgrau has announced the formation of a new PHP-related group in the New York City area, the Pro PHP NYC group.
We felt that the other handful of PHP Meetup groups in the area cater to those just starting out more often than not. The engineers who are serious about building professional, enterprise-level applications don't really have a group where they can consistently expect presentations on those topics.
The focus of the group is less on the basic "hows" and "whys" of PHP and more on things like performance/scaling, optimization, testing and application architecture. If you're interested in joining the group, check out < href="http://www.meetup.com/pro-php/">their Meetup page. There's no word (as of the time of this post) on when their first meeting will be, but it sounds like an interesting group.
2012年2月27日星期一
7php.com: Interview with Amit Singh - Organizer of PHPCamp.org
On 7php.com today there's another interview with a member of the PHP community posted - Amit Singh, an organizer of the largest Indian Unconference, PHPCamp.org
In this edition, I talked with Amit Kumar Singh The founder of AmiWorks. Amit (@onlyphp) is a very passionate developer and has been the organizer of the Biggest Un-Conference In Pune in 2008. Following this success, he founded PHPCamp.org. He was the guy who coined the famous "Pune Effect" in India. I have been specially enthusiastic with how he makes each of his projects a simple success by just having the mindset of "Experiments Never Fail" and hence do not hesitate at all in experimenting every of your (coding/projects) dreams.
Questions in the interview ask Amit about things like:
- His history with the PHP language
- Some of his advice to a beginner
- What resources (books, blogs, etc) he recommends
- How he usually debugs his code
- Where he sees the PHP ecosystem in five years
- More about his PHPCamp project/conference
Michael Nitschinger's Blog: RFC: li3_fixtures Rewrite
Michael Nitchinger has a new post to his blog about a rewrite for the Lithium framework - changing up the li3_fixtures plugin to make it a bit more of what the community needs.
The li3_fixtures plugin was my first Lithium plugin ever, and while it works okay, I feel there is a lot I can do to make it better and more flexible. In this post I want to share my ideas for a new fixture plugin and also want to gather feedback from the community to make it even more awesome.
He gives three instance where fixtures can come in extremely useful - making effective model unit tests with predictable data, mocking models with shortcuts to the data and mocking out web services. Want to add in your own suggestions for his refactor? Comment on the post!
Chris Hartjes' Blog: Simple API Testing Using Behat
Chris Hartjes has taken some of his first steps to testing a web service with the help of the Behat BDD testing framework. In this new post he shares some of that knowledge and a bit of code to help guide you if you'd like to get started yourself.
I have been trying to push my JavaScript skills lately by first playing around with Node.js to get a feel for event-driven server-side coding and by trying to build something semi-useful using Knockout. [...] After working with PHPUnit's "assert that the result matches expectations" philosophy, switching to using a behavioural approach has changed how I decide to approach actually testing something.
He shows how to define a "scenario" in a more recognizable sort of English. His example is testing a web service to ensure of a few things:
- the response is JSON
- it contains at least one transaction
- the first transaction has an ID, contains two teams and has a description
Included in the post is the resulting Behat test code (generated and modified with his testing details) and an example of the execution of the test.
I think that the BDD approach maps better to a results-oriented methodology when it comes to testing: you are using real-life scenarios to make sure that you are getting back the results you are expecting. In the end. that is still the goal of testing.
2012年2月24日星期五
Site News: Popular Posts for the Week of 02.24.2012
- Symfony Blog: Symfony Live 2012: Paris Edition
- Community News: The Great Web Framework Shootout
- Markus Pullmann's Blog: Remote Debugging in PHP with XDebug
- Sameer Borate's Blog: Building a adjacency matrix of a graph
- NetTuts.com: PDO vs. MySQLi: Which Should You Use?
- SpyreStudios.com: Connecting with API Data from Instagr.am using PHP
- Rob Allen's Blog: What problem does dependency injection solve?
- Dave Marshall's Blog: How I'm designing a RESTful(ish) web service
- PHPMaster.com: Creating Web Services with PHP and SOAP, Part 1
- Marcelo Gornstein's Blog: Sniffing in PHP using libpcap: Thank you SWIG!
PHP.net: PHP 5.4.0 RC8 released
The PHP project has officially announced the latest release candidate for the upcoming PHP 5.4.0 series - PHP 5.4.0 RC8.
The PHP development team would like to announce the 8th release candidate of PHP 5.4. PHP 5.4 includes new language features and removes several legacy (deprecated) behaviours. Windows binaries can be downloaded from the Windows QA site. THIS IS A RELEASE CANDIDATE - DO NOT USE IT IN PRODUCTION! This is the 8th release candidate. The release candidate phase is intended as a period of bug fixing prior to the stable release. No new features should be included before the final version of PHP 5.4.0.
Improvements in this release include bugfixes for an issues with htmlspecialchars/htmlentities as well as improving on the "max_input_vars" configuration setting to work better with nested variables. You can find the full list of changes in the NEWS file and download the release for testing from the QA site (Windows binaries).
Phil Sturgeon's Blog: My Thoughts on CICONF 2012 UK
Phil Sturgeon attended this year's CICONF 2012 (UK) and has shared some of his thoughts and experiences in a new post to his blog.
It's been a few days since CICONF and this is my first chance to get my thoughts together after a few busy days. In all I am extremely pleased with the event, and so far I have seen nothing but positive feedback on the #ciconf hash-tag and not heard any complaints. Winner!
He goes through both days of the conference - Friday and Saturday - describing things from his perspective (an organizer), some of the speakers that presented and some of the evening activities.
php|architect: 2012 Impact Awards Voting Opened!
As mentioned in this new post from the php|architect site, the voting for their 2012 Impact Awards has begun!
We at php|architect want to honor those who give of themselves so that we can work with PHP and in this great ecosystem. We are standing on the shoulders of giants and want to pause to say thank you. The full details can be found on the Impact Awards page. Voting is open through the end of March and is open to all php|architect subscribers.
The categories for this year's event are "Up & Coming", "Best Cloud Platform" and "Best PHP Application Platform". Nominees across all of the categories include Joind.in, PintLabs, AppFog, Pagoda Box Drupal 7 and SugarCRM. If you're a subscriber, get in there and vote for your favorites!
2012年2月23日星期四
Site News: Blast from the Past - One Year Ago in PHP
- Till Klampaeckel's Blog: Contributing to PEAR: Taking over packages
- Michelangelo van Dam's Blog: Book review: CMS Design Using PHP and JQuery
- DZone.com: Video: PHP 5.3.1, MongoDB and Lithium on Windows 7 / IIS 7
- Mayflower Blog: Creating coding standards for PHP_CodeSniffer
- php|architect: Creating RRD graphs in PHP
- NetTuts.com: Create your First Tiny MVC Boilerplate with PHP
- PHPBuilder.com: Using the Factory Pattern in PHP Applications
- NetTuts.com: Why You're a Bad PHP Programmer
- Najaf Ali's Blog: Why PHP is better than Ruby
- Gonzalo Ayuso's Blog: Speed up page page load combining javascript files with PHP
- Michael Maclean's Blog: Using Pango for PHP: a taster
- Michael Nitschinger's Blog: Understanding the Lithium Router - Part 2
- Community News: PHP UK Conference 2011 Almost Sold Out!
- Ruslan Yakushev's Blog: How to enable Xdebug in WebMatrix
- Anna Filina's Blog: Symfony - subfolders for partials
Chris Hartjes' Blog: Thoughts on Testing APIs
In this new post to his blog Chris Hartjes offers up a few of his own thoughts about testing APIs and some of the issues/concerns he's come across in his own testing (via Behat).
I have been asked a few times on Twitter for some advice on how to use testing tools in order to test APIs. It just so happens that I am writing a bunch of tests for an API at work so perhaps this is a very timely blog post. [...] When you are testing an API you main concern is your ability to reproduce the results of a specific API call. If your API is such that repeating a call several times will give you different results, you do have some challenges on your hands.
He talks about functional testing, the "moving parts" they involve, using only known data sources and the creation of integration tests. He also mentions the testing of your local application to ensure it's handling (or transforming) the results of the API calls into something useful.
In the end, it doesn't really matter what tools you are using to test either your own APIs or ones that your application depends on. Be clear in your mind about what it is you are actually trying to accomplish and don't get create tests that provide very little value to your application.
Rob Allen's Blog: Overriding module configuration in ZF2
In a quick new post to his blog, Rob Allen shows how you can override a module's configuration in a Zend Framework 2 application. In his example, he uses the "User" module and overrides two of the "magic paths" it creates.
Let's say that you install the ZF-Common's User module. By default, it sets up its routes under the /user path segment. [...] This config section will create the routes /user and through the magic of child_routes, also create /user/login and other required routes. If you don't want /user and would prefer /member, then it's easy enough to change. Just add a new config file to the project's config/autoload folder.
Code for the configuration files is included with the update to the "ZendMvcRouterRouteStack" to change the ZF-Common User module's setup to point to "/member" instead of "/user" when routed. You can find out more about the module system in ZF2 in the latest version of the manual.
Cal Evans' Blog: Don't Hire PHP Community Members!
Cal Evans has posted a great tongue-in-cheek post to his blog today giving reasons why you shouldn't hire PHP community members to work at your company.
It is no secret that I spend a lot of time promoting the PHP Community. It is a vibrant, helpful and friendly community and I've said before that I believe it to be one of the most important asserts of the PHP language. I'm also a realist though; I've built teams and I've hired developers. [...] I have experience in this area and I have strong opinions. I am going to share one of those opinions with you right now: Don't hire developers who are active members of the PHP Community.
His list of "don't hire" reasons are:
- PHP community members solve problems
- If they can't solve a problem, they usually know who can
- They love to show off
- They make their employers look good at conferences.
- They work for free
For each topic, he gives a brief summary explaining its relation to the "don't hire" mentality. Reading between the lines, you'll see his true message, though - PHP community members have a lot to offer you and your business. Their visibility and experience (and connections) can only benefit the work they do.
2012年2月22日星期三
Community News: Dutch PHP Conference Schedule Announced!
The Dutch PHP Conference has officially announced their schedule for this year's event and the opening of the registration (Early Bird pricing ending April 1st).
We are happy to announce that we have just published the schedule and registration is now open. Quickly, go and check out all the great content we have to offer this year! Once you've decided that you want to join us, you can go to the registration page to order your tickets. Please note that you will get a 15% early bird discount if you order your tickets before 15th April. Ticket prices were announced last week and can be found in this blogpost.
Topics in this year's event include:
- Testing with Behat
- Zend Framework 2
- Backbone.js
- OAuth
- Elastic Search
- RESTful web services
- Puppet
- Coding/deploying/scaling with Amazon AWS
You can get your tickets on their registration page with the early bird pricing for all tickets lasting until April 1st. When ordering the full pass or tutorial-only, you will be asked to specify the tutorial you wish to attend.
Dave Marshall's Blog: How I'm designing a RESTful(ish) web service
Dave Marshall is in the process of building a "RESTish" web service and has shared some of his planning steps in a new post to his blog.
This post is going to describe how I've ending up designing, what I consider to be a fairly RESTful web API. I'm far from being an expert, and this is definitely the closest thing to a RESTful API that I've ever created, so I'm not even experienced with REST APIs. [...] Until about 6 months ago, I'd always been sceptical of creating RESTful APIs, but I think I've had a few pennies drop since then that have made me fairly confident that I grasp the basics pretty well.
He touches on topics like: authentication, the Richardson Maturity model, HTTP verbs, sample request and response messages and some BDD-style tests to predict the output of a basic request.
2012年2月21日星期二
Voices of the ElePHPant: Interview with Matthew Weier O'Phinney
On the Voices of the ElePHPant podcast today Cal Evans has posted the latest interview with a member of the PHP community. This time it's Matthew Weier O'Phinney, lead on the Zend Framework project.
Cal's "three questions" for Matthew were:
- Since Zend Framework is the opposite of the ideals behind the Micro PHP Manifesto, what are your thoughts on it?
- Zend Framework 2 is close but not done - should a new project go with v1 or v2?
- What's your local user group and it's URL (hint: there's not one yet)
You can listen to this latest episode either via the in-page player, by downloading it directly or by subscribing to their feed.
PHPMaster.com: Creating Web Services with PHP and SOAP, Part 1
On PHPMaster.com today there's a new tutorial posted, the first part in a series, showing how to create SOAP web services with the help of the NuSOAP library.
In this first of a two part series on web services I'll talk about the SOAP specification and what is involved in creating SOAP messages. I'll also demonstrate how to create a SOAP server and client using the excellent NuSOAP library to illustrate the flow of SOAP. In the second part I'll talk about the importance of WSDL files, how you can easily generate them with NuSOAP as well, and how a client may use a WSDL file to better understand your web service.
He introduces you to the concepts behind SOAP, the normal structure of a SOAP-formatted XML message and what an example might look like for fetching a stock price from a remote service. He then shows how to use NuSOAP to create both a simple server and client to pull information about books - sample code and a screenshot of the output is included.
2012年2月20日星期一
7php.com: Interview with Chris Hartjes - The "Grumpy Programmer" of the PHP Community
7php.com has posted their latest interview with a member of the PHP community - Chris Hartjes, the "grumpy programmer".
In this edition I talked with Chris Hartjes (@grmpyprogrammer), the co-organizer of the GTA PHP User Group (@gtaphp). Chris is a real Grumpy PHP Programmer! But grumpy in a very positive sense though. He focuses his effort in applying and transcending his best practice ideals with the codes he write. I would tag him as the "perfectionist programmer"; he will not hesitate to scrap his piece of work if he finds a fault or a room for improvement and start all over again with that "eye for perfection". In this interview, he will talk a bit about those coding best practices fortunately.
Chris answers questions about:
- His history with PHP
- His favorite PHP book
- What tools he uses (IDE)
- His description of the PHP community
- His favorite conference
You can read the answers to these and more in the full interview.
Rob Allen's Blog: What problem does dependency injection solve?
In his latest post Rob Allen seeks to answer the question "what problem does dependency injection solve?":
Zend Framework 2 comes with a dependency injection container (DIC), as does Symfony 2 and Aura, along with many other PHP frameworks that target PHP 5.3 or hight nowadays. This article attempts to explore the problem that a DIC tries to solve.
He gives an example (somewhat based on the same structure of his Zend Framework tutorial) showing how you could use DI to inject the Artist object into the Album object. This allows for more flexibility if more Artist types are added (extending the main Artist, of course). His second example shows how to use a DIC to hold album information.
2012年2月17日星期五
Site News: Popular Posts for the Week of 02.17.2012
- Reddit.com: What non-PHP stuff should a PHP developer know?
- Dave Gardner's Blog: PHP Deployment with Capistrano
- 7php.com: PHP Interview with Cal Evans - Get Involved if you want to be a Pro PHPer
- John Conde's Blog: My experience seeking employment as a PHP developer
- PHPMaster.com: Autoloading in PHP and the PSR-0 Standard
- Pim Elshoff's Blog: Dependency management
- Cloud Out Loud Podcast: Interview with Ed Finkler
- Robert Basic's Blog: Zend Framework full page cache tips
- Community News: The Changelog Podcast
- Sameer Borate's Blog: Building a Graph data structure in PHP
Markus Pullmann's Blog: Remote Debugging in PHP with XDebug
Markus Pullmann has a new post to his blog about setting up XDebug in your PHP installation to help you narrow down those elusive issues more quickly.
Debugging locally is a nice improvement to have no debugger at all, but in many situations there is the need to debug on production server, where the application is running on the web. There are different reasons for that, but the most important one for me is, that my local environment / installation is different from the one i have on servers in data center and bugs can be related to the environment.
He walks you through the installation and server-side configuration of XDebug first then shows how to install the Komodo Remote Debugging Client to help with multi-user debugging setups. He mentions setting up the debugging on the client/IDE side, but there's no specific instructions for any particular IDE - just how it works overall.
Sameer Borate's Blog: Building a adjacency matrix of a graph
Building on the graphing tutorial in his last post Sameer continues on looking at graphs in PHP with this new post showing how to create an "agency matrix" of a currently built graph.
Building a graph is not enough; we also need the ability to search through it. To make it easier to build search algorithms, it is useful if we can represent the graph and its connections in a different way; adjacency matrix being one such representation. An adjacency matrix is a means of representing which vertices (or nodes) of a graph are adjacent to which other vertices.
He includes some sample code to extract the data from a graph (built with the PEAR Structures_Graph package) and create a basic "table" of information about each nodes' connections.
SpyreStudios.com: Connecting with API Data from Instagr.am using PHP
On SpyreStudios.com there's a post showing you how to connect to the Instagr.am API and pull data back with a bit of simple PHP.
The process of connecting into API data via OAuth is tricky. Some of the more notable social networks which have adopted this technology include Foursquare, Twitter, and Facebook. But Instagram is a very popular mobile app which has grown tremendously fast. Their recent API v1.0 release has some really neat features where you can pull popular photos, recent users, follower lists, and a whole bunch more.
He points to the Instagr.am PHP API scripts that the service already provides and shows how to set up an application on your Instagr.am account. This application then has OAuth keys you can use to connect to the service (via the PHP API scripts) and pull back basic user information - profile picture, number of photos, followers, etc. There's also a live demo you can test out.
2012年2月16日星期四
Site News: Blast from the Past - One Year Ago in PHP
- Brian Swan's Blog: Do Stored Procedures Protect Against SQL Injection?
- Phil Sturgeon's Blog: PHP Format abstraction with a simple class
- Elliot Haughin's Blog: CodeIgniter 1.7.x, 'Core' 2.0, CodeIgniter Reactor, Bitbucket, Zips...
- Berry Langerak's Blog: Getters and setters: evil or necessary evil?
- Web Development Blog: Why should you cache your PHP website?
- Zend Developer Zone: A little fun with the average tech salaries as reported by dice.com
- Lorna Mitchell's Blog: Callbacks in PHP
- PHPBuilder.com: Harness the Scripting Power of PHP and cURL to Update Facebook
- Cal Loveless' Blog: On Continuous Deployment
- Lorna Mitchell's Blog: Using Gearman from PHP
- WebDev Radio Podcast: Episode 84: Travis Swicegood
- Community News: Dutch PHP Conference Ticket Sales Open
- Community News: Voices of the Elephpant Podcast
- Rob Allen's Blog: Using your own View object with Zend_Application
- Phil Sturgeon's Blog: Getting involved with CodeIgniter
Rob Allen's Blog: A primer on PHP namespaces
For those that either haven't worked much with PHP 5.3 in their applications (or just haven't gotten around to using the feature) Rob Allen has put together an introduction to namespaces to guide you through some first steps and share some example usage.
I know that there are a lot of posts now about namespaces in PHP 5.3. This is mine which is how I learnt how they work. [...] That is, namespaces allow us to: combine libraries with the same classnames, avoid very long classnames and organise our code easily. Note that namespaces do not just affect classes. They also affect functions and constants.
He starts with the basic namespace definition (using the "namespace" keyword), shows how to import another namespace with "use" and the use of the __NAMESPACE__ constant to determine what namespace you're operating in. More information on namespaces can be found in the PHP manual.
PHPMaster.com: Packaging Your Apps with Phar
On PHPMaster.com today there's a new tutorial showing you how to package up your applications using the phar functionality that's bundled in to recent PHP versions.
PHAR ("Php ARchive") is analogous to the JAR file concept but for PHP. If you have PHP 5.3 or greater, the Phar extension is built-in and enabled; you can start using it without any additional requirements. This article is intended to shed some light on this important feature for those who haven't used it before. Hopefully you'll find it a very helpful tool and have a better and faster deployment experience.
They show you how to create a sample project to build the phar from - a simple application that prints out a message and the contents of a configuration file. Code is included to help you build the phar file and how to define the stub file to pull in your application's files and folder.
2012年2月15日星期三
User Group: Boston PHP Welcomes Chris Shiflett
The Boston PHP User Group will be having their next meeting tonight (the 15th) at 7pm at the Microsoft N.E.R.D Center in Cambridge. The featured speaker for the evening is Chris Shiflett, a well-known member of the PHP community. He'll be speaking on "Security-Centered Design: Exploring the Impact of Human Behavior".
Join Boston PHP and O'Reilly Author Chris Shiflett as we take you through a fascinating talk on the human behavior and social aspect of security. We'll explore topics such as change blindness and ambient signifiers, and we'll show some real-world examples that demonstrate the profound impact human behavior can have on security. If your a designer, developer, human interaction designer, you won't want to miss this talk.
So far there's over 150 marked as attending - if you plan on trying to make it tonight, be sure you RSVP so they know how many to expect.
Chris Hartjes' Blog: Organzing Slim Framework Applications
One of the more popular PHP microframeworks right now is Slim and Chris Hartjes has a new post to his blog about a good way he's found for organizing applications that use this handy tool.
I've never really used a microframework in PHP before. I used Flask for a Python project that I did to experiment with using Google App Engine. The principles seem to be quite similar (although I will admit that having decorators in PHP would be ineresting) but the trade-off with a microframework is that you usually have to figure out an application layout for yourself.
He also uses the Pimple dependency injection container, Twig templating and Composer for package management. He describes how he got it all set up - organizing the code so Composer could understand it, creating the Twig templates directory and creating some of his default routes.
Sameer Borate's Blog: Building a Graph data structure in PHP
In the latest post to his blog Sameer Borate takes a look at using the Structures_Graph package from PEAR to create data structures in PHP with linked nodes for directed and undirected graphs.
The Pear Structures_Graph package allows creating and manipulating graph data structures. It allows building of either directed or undirected graphs, with data and metadata stored in nodes. The library provides functions for graph traversing as well as for characteristic extraction from the graph topology.
After sharing the one-line install, he shows how to create some instances of the package's Nodes and how to connect them to a graph and link them to other nodes. He includes a few examples - a simpler one with multiple nodes joined in a directed graph, another showing how to associate data with a node and how to query the graph for node connections and testing to see if the graph is acyclic.
2012年2月14日星期二
UMumble.com: Working with memory
On the UMumble blog there's a recent post looking at memory consumption in PHP applications - what PHP does for you when managing how it uses your system's memory and what you need to worry about in your code.
There is a widespread view that the ordinary PHP developer does not need to control memory management, but "controlling" and "knowing" are slightly different concepts. I will try to throw light upon some aspects of memory management when working with variables and arrays, and some interesting pitfalls of the internal optimization of PHP. As you can see, the optimization is good, but if you do not know exactly how it is optimized, you might meet the pitfalls, which can make you pretty nervous.
They talk about some of the basics - how variables are stored in hash tables and how this helps memory consumption - as well as using the memory_get_usage method to find your current consumption. This is show for both regular strings and arrays, comparing larger data (and assigning it multiple times) to simpler structures. They also mention how PHP handles memory usage in passing by reference and copying of values.
PHPMaster.com: Under the Hood of Yii's Component Architecture, Part 3
PHPMaster.com is back with the third part of their series looking at the internals of the Yii framework (specifically, its components). In this latest article Steven O'Brien focuses on how the framework uses behaviors.
A behavior, as it is called in Yii, is a manner of combining objects at runtime to extend an object's functionality. Behaviors are an excellent way to decouple code and keep ever expanding systems maintainable. [...] We can not reuse our code effectively because PHP doesn't support multiple inheritance. The Yii behavior system is a way of achieving multiple inheritance by implementing mixins.
He gives an example of working with a user that's connecting to your application just to get to a third-party billing system. They show how to take this functionality our of your generic "User" class and make a behavior out of it. This functionality can then be attached to the User object (via an attachBehavior call) and used directly. He gets into how Yii does this magic, showing how it appends it to a special value in the class and the __call method checks the method call to see if it exists in one of these special classes.
John Conde's Blog: My experience seeking employment as a PHP developer
John Conde has shared some of his recent experience when he began job hunting as a PHP developer. If his experience is any indication, it's clearly a good time to be a (qualified) PHP developer.
I created my profile on monster.com on a Monday and made it public that night. The following Tuesday morning my telephone went nuts and my email inbox blew up with recruiters reaching out with positions that I was "perfect for". Over the course of the next week and a half (not including weekends) I spent 10-12 hours a day receiving and returning phone calls, and reading and responding to emails from recruiters.
He received calls from all over the country as well - "apparently experienced PHP developers are in short supply". He points out a few things he found interesting about the search like the fact that unit testing was never listed as a requirement (or even a "plus") in descriptions, only a few descriptions talked about memcache and that PHP wasn't the language over half of the employers were looking for.
He also shares a few hints for those looking for jobs right now, things to add to your resume or look for as far as skills most in demand:
- Have experience with frameworks
- Joomla was very commonly being used so being familiar with it is definitely a plus
- Have sample code to show your coding skills
- There's more to the world then PHP
2012年2月13日星期一
7php.com: PHP Interview with Cal Evans - Get Involved if you want to be a Pro PHPer
On 7php.com today there's a new interview with a well-known member of the PHP community - Cal Evans:
In this edition I talked with Cal Evans, the Icon Of The PHP Community. He is to the PHP Community what Pele is to the Football world, just to tell you about the influence he has on the PHP world. He shares, helps, mentors, propagates PHP wherever and as much as he cans. He was previously Chief editor of Zend Technologies (@Zend), worked for iBuildings (@ibuildings) one of the biggest PHP service companies in Europe where he lead the growth of a PHP Center of Expertise and ex Mister ZendCon (@zendcon).
In the interview questions ask include topics like:
- How he started with PHP
- His thoughts on the good and bad parts of the language
- How he suggests getting involved in the PHP community
- The best PHP book he's read
- What tools he uses in his development
- A framework recommendation
- and how he defines "the PHP community"
Rob Allen's Blog: Using ZendLoaderAutoloader
In a new post to his blog Rob Allen introduces you to the autoloader that comes with the Zend Framework 2 and shows how to use it to load your own classes.
Autoloading is the process in PHP whereby the system attempts to load a class when it is first encountered (via new or via class_exists) if it hasn't already been loaded via a require or include. Autoload works by looking for a method called __autoload or walking through any method registered with spl_autoload_register. Zend Framework 2 provides the ZendLoaderAutoloader component for autoloading of Zend Framework and your own classes.
The PSR-0-standard tool allows you to load files, set up class mapping and allows for multiple autoloading methods to work side-by-side. He shows how to use the standard autoloading functionality to define paths to locate files (with prefixes and namespaces) in both a constructor-based setup and a more programatic approach. He also shows how to use the ClassMapAutoloader to load from a mapping of class name to class file. Wrapping it up, he shows how to combine the two methods into a single ZendLoaderAutoloaderFactory instance.
Davey Shafik's Blog: The Blowfish Debacle
Davey Shafik has a recent post to his blog about what he calls "The Blowfish Debacle" - the issues that came up with the PHP 5.3.7 release to upgrade the crypt_blowfish version that resulted in a larger error being introduced.
This was a great security fix, solving an issue with insecure passwords due to incorrect behavior. HOWEVER, what wasn't made clear, is that this change was actually a backwards compatibility break. If you upgraded to 5.3.7+ data hashed pre-5.3.7 would no longer match data hashed post-5.3.7; this means if you use it for passwords, it will no longer match. So what's the deal here?
He talks about the differences in the two methods of encryption, the newer being the "more correct" way of doing things. If you need the backwards compatibility because of previously hashed values, you can use the "$2x$" prefix instead of the usual "$2a$". He includes a snippet of code that can be used to upgrade all of your previously hashed blowfish passwords up to the new format.
2012年2月10日星期五
Site News: Popular Posts for the Week of 02.10.2012
- Etsy Code as Craft: Rasmus Lerdorf - PHP in 2012
- Chris Hartjes' Blog: How Not to Suck at PHP
- PHP.net: PHP 5.3.10 Released (Security Fix - Recommended Upgrade)
- Henrik Bjørnskov's Blog: Symfony2: Using the validator symfony1 style
- Freek Lijten's Blog: Currently on PHP's internals - Property Accessors
- PHPMaster.com: Tracking Upload Progress with PHP and JavaScript
- PHPClasses.org: Another Serious Security Bug on PHP 5.3.9
- Mayflower Blog: Zend Framework Application.ini Cheat Sheet
- Artur Ejsmont's Blog: How to build mongodb pecl extension in 32bit for PHP 5.2 on OSX Snow Leaopard
- Developer Drive: Building a PHP Ad Tracker: Data Object Design and Coding
Community News: The Changelog Podcast
If you're a fan of open source development and can't get enough about projects and what's the latest in the online OS community as a whole, you'll definitely enjoy The Changelog (it's a weekly podcast and news site).
The podcast hosts talk about popular trends and technology in the open source world and interview developers behind some of the useful tools you may use every day. Recent topics include Vagrant with Mitchell Hashimoto, Spine and client-side MVC with Alex MacCaw and Foundation and other Zurb goodies.
They've also spotlighted several interesting new libraries including:
Reddit.com: What non-PHP stuff should a PHP developer know?
On Reddit.com there's a good discussion going on to answer the question "What non-PHP stuff should a PHP developer know?"
I was looking at job description for a web developer, and one of the big responsibilities was database maintenance. [...] And along those lines, what other skills would be useful for a PHP developer to have that aren't directly PHP-based?
Suggestions so far include things like:
- Linux command-line skills
- some Python
- Virtualization (making and administering VMs)
- Version control systems (svn or git)
- Database architecture
- HTML/CSS/Javascript
2012年2月9日星期四
Refulz.com: The __toString() Method - Objects as Strings
On the Refulz.com blog there's a recent post introducing the __toString() magic method in PHP. This handy method allows you to define how to return an object when it's referenced as a string.
We started the study of PHP magic methods by learning about __get() magic method. [...] PHP is loosely typed language and same variable can be used or referred as string, number or object. The __toString() method is called when the code attempts to treat an object like a string. This function does not accept any arguments and should return a string.
Some quick code is included showing how it works - returning a combined string made from two private class properties when the object ($obj) is echoed out. They also show multiple ways of using the method in both pre- and post-PHP 5.2.
SitePoint.com: How to Create Your Own Random Number Generator in PHP
On SitePoint.com today there's a new tutorial showing how to create a random number generator in PHP (with the help of methods like mt_rand and mt_srand).
Computers cannot generate random numbers. A machine which works in ones and zeros is unable to magically invent its own stream of random data. However, computers can implement mathematical algorithms which produce pseudo-random numbers. They look like random numbers. They feel like random distributions. But they're fake; the same sequence of digits is generated if you run the algorithm twice.
Included in the post is code showing how to use the random functions and how to create a class (Random) that provides a few methods to help make generation easier - "seed" and "num". It first calls "seed" with a number to start the random generator off with and then "num" in a loop to pull out random values based on that.
2012年2月8日星期三
Gonzalo Ayuso's Blog: How to protect from SQL Injection with PHP
In a recent post to his blog, Gonzalo Ayuso shares a few tips on preventing SQL injection attacks on your applications.
Security is a part of our work as developers. We need to ensure our applications against malicious attacks. SQL Injection is one of the most common possible attacks. Basically SQL Injection is one kind of attack that happens when someone injects SQL statements in our application. You can find a lot of info about SQL Injection attack. Basically you need to follow the security golden rule: "Filter input, Escape output".
He advocates the use of the PDO abstraction layer to filter out a lot of the issues. Using its prepared statements, you can easily strip out things that just adding slashes to user input wouldn't prevent. He also includes a reminder about database permissions - allowing only certain users the ability to, for example, delete can help provide one more level of security (in other words, don't use a "super user" in production).
Rob Allen's Blog: One-to-Many Joins with Zend_Db_Table_Select
Rob Allen has a tip for the Zend Framework users out there using the Zend_Db module to connect to their database resources - how to do a one to many join with the help of Zend_Db_Table_Select (easier than it sounds).
Let's say that you want to set up a one-to-many relationship between two tables: Artists and Albums because you've refactored my ZF1 tutorial. [...] Assuming you're using Zend_Db_Table, the easiest way is to turn off the integrity check and do a join in a mapper or table method.
He includes a few lines of source to illustrate, calling the "setIntegrityCheck" value to "false" to tell ZF not to worry about the additional join value over to the artists table. The result is a new column value with the artist's name instead of just the ID.
2012年2月7日星期二
Voices of the ElePHPant: Interview with Elizabeth Naramore
The Voices of the ElePHPant podcast has released their latest episode (one recorded a while back) - an interview with Elizabeth Naramore, a well-known PHP community member.
This episode was recorded in 2011. Elizabeth now works for Orchestra.io. It's still a fun interview though because...well, it's Elizabeth.
You can find her blog here and follow her on Twitter here. If you'd like to listen to this latest episode, you can either listen in-page or download the mp3 directly.
Brandon Savage's Blog: New Rockville PHP Group
If you're in the Montgomery County, Maryland area and are a PHP developer looking to reach out and meet others, you should check out this new post from Brandon Savage. He's trying to start up a user group in that area.
There are lots of active, vibrant developer groups in the DC area: DC PHP, Baltimore PHP, and the Frederick Web Tech group. The DC PHP Beverage Subgroup meets monthly in Northern Virginia. But in the middle between all these groups lies Montgomery County, Maryland. In that area live hundreds of developers who struggle to reach any of the developer groups in the area on a weeknight. It's time to build them something of their own.
His focus is the Montgomery County area so as not to directly take away from any of the other groups in the area people already attend. If you're interested in a group in that area, leave him a comment or hit him up on Twitter.
NetTuts.com: Turbocharge your Website with Memcached
On the NetTuts.com site there's a new tutorial showing you how to introduce the Memcached tool to your application - a quick and easy way to cache data and optimize performance.
Your latest PHP/MySQL website is finally online. And it's awesome. But it's not as fast as you want it to be, because of the many SQL queries running every time a page is generated. And above that, you have the feeling it will not scale well under heavy loads. And you are most likely right. In this tutorial, we will see how you can greatly improve your website's responsiveness [...] by implementing a cache layer between your code and your database. The good news is it is fairly easy, and can be done in a few minutes!
They help you get the memcached server installed (a one-liner in most linux distributions) and how to install the memcached extension using PECL. Code is included showing you how to connect to the server, store data into the cache based on a generated key and how to pull the same data back out.
2012年2月6日星期一
7php.com: PHP Interview With Ivo Jansch Founder & CEO of Mobile Technology Egeniq
7php.com has posted a new interview with a PHP community member today - this time it's Ivo Jancsh (formerly of Ibuildings) now CEO at Eginiq, a mobile development company.
In this edition I talked with Ivo Jansch (@ijansch) ex-CTO of Ibuildings which is one of the biggest PHP service companies in Europe. Ivo is known for his involvement in evangelising the use of PHP technology in enterprise environments. He is also the PHP 5.x Certification Advisory Board Member at Zend Technologies. You can read more about Jansch on his blog.
The questions asked include the usual with a few extras thrown in:
- How did you start with PHP?
- To someone who wants to become a better PHP developer, what is your advice?
- How do you debug your PHP code, do you use something like xdebug or krumo..etc?
- In the next 5 years, how do you foresee the PHP ecosystem
- If you had to go back in time, would you still choose PHP?
Joshua Thijssen's Blog: Setting up a development environment
In a new post to his blog Joshua Thijssen gives a guide to how he usually sets up his development environments when working in PHP. It includes working with virtual machines, configuring DNS and setting up his tools to work with it all.
Doing development on multiple projects can be a burden from time to time. One project would be running on PHP 5.3, while another still needs 5.1. Sometimes you need a MySQL server, while on other occasions, you need a NoSQL solution like couchDB or MongoDB together with all kind of gearman functionality. This article shows you how I've setup such a development platform that allows you to quickly create new projects, and still maintain flexibility when you need it.
He uses VirtualBox with either a Debian or CentOS installation as a base platform. He uses Vagrant to set up and configure the machines to make setup almost automatic. He still has to go in and configure a few things like the VirtualHost and DNS settings for the site/application he's working on.
Next up is setting up the tools he uses, specifically XDebug and setting up his editor of choice (PHPStorm) for remote debugging.
Stuart Herbert's Blog: PHPUnit Plugin For Sublime Text 2
Stuart Herbert has officially released a plugin for the popular text editor Sublime Text 2 to integrate PHPUnit support directly into the editing environment.
Sublime Text 2 is a new cross-platform text editor that I've recently switched to. It's still in public beta, but already offers better performance (and battery life!) and a better look (fonts that render properly!) than Java-based IDEs such as Netbeans. One thing it didn't have was support for PHPUnit, so I've made a plugin. It's available to install via Package Control.
The plugin allows you to directly create tests for a class using a context menu's "Test This Class" option. You can also run the tests directly from the editor and use either the menu or direct text commands to control it. He's also gathering some other well-used PHP snippets into another related plugin, the Additional PHP Snippets plugin.
2012年2月3日星期五
Site News: Popular Posts for the Week of 02.03.2012
- /Dev/Hell Podcast: Episode 4: The Cool Kids Club
- Project: Patchwork-UTF8 - UTF8 Support for PHP
- Anson Cheung's Blog: Top 10 PHP Best Security Practices for Sys Admins
- Charles Sprayberry's Blog: Why you should use DI
- Alessandro Nadalin's Blog: Managing PHP dependencies with composer
- Mike Wallner's Blog: Dropping server load with HTTP caching
- DevShed: PHP Closures as View Helpers: Lazy-Loading File Data
- AndroidHive: Android Login and Registration with PHP, MySQL and SQLite
- Lorna Mitchell's Blog: PHP 5.4 Built In Webserver
- PHPMaster.com: Under the Hood of Yii's Component Architecture, Part 1
PHP.net: PHP 5.3.10 Released (Security Fix - Recommended Upgrade)
The PHP development team has officially announced the release of the latest version of PHP in the 5.3.x series - PHP 5.3.10:
The PHP development team would like to announce the immediate availability of PHP 5.3.10. This release delivers a critical security fix. [...] Fixed arbitrary remote code execution vulnerability reported by Stefan Esser, CVE-2012-0830.
It is highly recommended that users upgrade to this latest version to avoid falling victim to this recently introduced bug relating to the new "max_input_vars" setting added to protect from the overflow issue recently brought up in the PHP community.
Freek Lijten's Blog: Currently on PHP's internals - Property Accessors
Freek Lijten has posted another "Currently on PHP's internals..." post to his blog today (here's the previous one) with a look at the discussions around the idea of having "property accessors" in PHP - a standardized way of defining getters/setters in objects.
Today I will be discussing a feature that at this moment is called "Property Accessor". It is a method of defining getters and setters. Originally an RFC was defined as early as september 2009, but recently new discussion took place and an actual patch was created. There is no certainty this feature will ever make a PHP version but discussion seems to target implementation details and not the feature itself, so things are looking bright for this feature.
There's two RFCs posted about the topic - the original proposal (from Dennis Robinson) and a patch for implementing them (from Clint Priest). The proposal replaces the common magic getters/setters (__get & __set) with the optional "get" and "set" keywords inside of custom-defined properties.
2012年2月2日星期四
Site News: Blast from the Past - One Year Ago in PHP
- Chris Hartjes' Blog: Book Review: PHP 5 Social Networking
- Rob Allen's Blog: Zend Framework 2 in Action
- Mike van Riel's Blog: Introducing: DocBlox
- SocialDevelopers.net: Facebook and the Zend Framework - Part 1: Iframe Authentication
- Binpress.com: Web Developer Programming Contest
- Matthew Weier O'Phinney's Blog: Why PHP Namespaces Matter
- Michael Feichtinger's Blog: PHP5 WebSocket Example - A Simple Chat
- Greepit.com: Behavior Driven Development Framework for PHP: Behat
- CodeIgniter.com: CodeIgniter 2.0.0 Released
- Steve Francia's Blog: On Symfony2
- Joshua Thijssen's Blog: Password hashing and salting
- Volker Dusch's Blog: Setting up Jenkins for PHP Projects
- InfoWorld: InfoWorld review: Fabulous PHP frameworks
- Strattonbrazil's Blog: php to python: Why PHP is now dead to me
- Gonzalo Ayuso's Blog: Function decorators in PHP with PHPDoc and Annotations
PHPMaster.com: Where on Earth are You?
In PHPMaster.com's latest tutorial Lukas White introduces you to using the Yahoo "Placemaker" web service to geographically locate a place from a free-form text string. The results include "place details" like the type of the location, latitude, longitude and how confident they are in their match.
The challenge then is to do two things: work out what place you could be talking about, disambiguate if necessary, and then identify exactly where on Earth that is. That's what I'll show you how to do in this article; by using a freely available web service, we'll write a simple program to ask users where they are (and ask them to clarify if necessary) before identifying their responses in concrete terms.
He shows how to make a request to the Placemaker web service, passing it a string coming from the user, to be located. The POST request contains a few pieces of data including an application ID
, your desired output type and the language you're using for the input. His example code uses curl to make the request and handles it (the XML response at least) with a call to simplexml_load_string.
Script-Tutorials.com: Form Validation with Javascript and PHP
On the Script-Tutorials.com site today there's a new tutorial about form validation using a combination of jQuery on the frontend and PHP on the backend.
In this tutorial, I will show you how to create an attractive, pleasant to look form for your website and then I will explain you how to dynamically validate them using Javascript. We'll also cover server-side validation with PHP to make everything 100% safe. This tutorial will help you to add more functionality to your forms which leads to better user experience and better quality of your website.
His sample form (name, password, email and gender) is made from some pretty simple HTML markup. The real trick comes with the jQuery validation on each field handled in an onKeyUp. Included are both a "password strength" method and an email validation method to check the format of the address. Errored fields have their background color changed to indicate that they've failed and some basic validation (length, password match, etc.) are also included. The PHP does much of the same validation once the form is posted and returns any error messages that might have come up.
You can download the code or try out a live demo to see the scripts together in action.
2012年2月1日星期三
Mike Purcell's Blog: PHPUnit - How to Run PHPUnit Against a Specific Test
Mike Purcell has a quick new post to his blog showing how you can run PHPUnit on one specific test using handy grouping functionality already built into the tool.
The other day I was debugging an error in one of my unit tests, and found it hard to track down because when I ran PHPUnit, it ran all the tests contained in the file where my problem unit test was located. After some Googling and reading the PHPUnit Api Docs, I found that you can specify a test, among other tests, by adding a comment with the @group annotation.
Using this "@group" annotation tells PHPUnit to combine these tests and allows you you specify a "--group" setting on the command line to only run those. He includes some sample code showing how it can be used. This can be very useful for combining results for certain kinds of tests (say, all related to bugfixes) without having to run everything all over again.
Ian Barber's Blog: Presentation Tips from Benelux
In this recent post to his blog Ian Barber offers up some hints on presenting at conferences (or other events really) based on some of his experiences at this year's PHP Benelux Conference that just wrapped up in Belgium.
Some of the conversations I had during the weekend were around technical presenting at conferences and usergroups, so I thought I'd collect a handful of the tips that were discussed into a post, and use a few of my favourite speakers at the event to illustrate them.
He has it broken up by speaker, first David Zülke, Rowan Merewood and David Coallier, each with their own highlights of what they did well in their presentations. The list includes:
- Make concepts concrete with examples and demos
- Care About The Visuals
- Project Confidence
- Engage The Audience
Ian provides summaries for each of the points, describing what the speaker did to accomplish it and how it could be put into practice by other presenters.