2012年3月6日星期二
Ilia Alshanetsky's Blog: Performance Analysis of isset() vs array_key_exists()
Ilia Alshanetsky has posted about a performance difference he's found between using the isset and array_key_exists functions in PHP to see if a value exists.
At Confoo I had an interesting conversation with Guilherme Blanco regarding the fact that in Doctrine 2 they had a performance issue due to usage of array_key_exists() and how it was significantly slower than isset(). His anecdotal example was that doing isset() took 0.5 seconds, while array_key_exists() for the same operation took 5 seconds! That seemed wrong [...] so, I've decided to do a quick benchmark using a 5,000 element array.
His benchmarking code is included - it just loads up a simple data set from a file of "words" and measures the microtime between the isset and array_key_exists calls. His results do show that isset is the faster of the two (by 2.5x) but it's still a super small micro-optimization that won't gain you much in the end.
The bottom line is that if your application does not need to distinguish between an array key that does not exist and one whose value happens to be NULL you should use isset() because it happens to be a little faster.
Ben Ramsey's Blog: Build PHP 5.4 on CentOS 6.2
In this latest post to his blog Ben Ramsey shows you how to, inside of a virtual machine, set up a server with PHP 5.4 installed (using CentOS 6.2).
In case you haven't heard the news, the PHP project released version 5.4.0 last Thursday. Naturally, I decided it was time to install and give it a try. I chose to install to a clean and bare-bones CentOS 6.2 virtual machine using VirtualBox. I did this for two reasons: 1) I wanted a clean environment for the build, and 2) I wanted to play with CentOS. At the time of this writing, there are not yet any official CentOS RPMs for PHP 5.4, so I had to build PHP from source. What follows are the notes I took during the installation and build process. I hope you find them helpful.
His instructions cover the full process:
- Installing the CentOS operating system
- Creating a non-root user
- Setting up the network for local access
- Installing the packages for PHP (via yum)
- Grab PHP 5.4 and compile it
- Testing out the web server with a sample phpinfo file
He includes a lot of extensions in his installation, some you may not need like pspell, tidy, calendar, ftp or xsl.
2012年3月5日星期一
7php.com: Interview Stuart Herbert - Become a Software Archaeologiest
On the 7php.com site today there's a new interview in their PHP community series, a talk with Stuart Herbert of the Phix project:
In this edition I talked with Stuart Herbert (@stuherbert), a highly highly and highly experienced software engineer. His interview is packed with insights and experienced thoughts. Herbert is one of those rare experienced geek who also teaches the principles of T'ai Chi Ch'uan. Stuart has been involved in almost everything out there in the Programming sphere; he's a conference speaker, author of books, author for magazine articles, does pod-casts, volunteer developer for Gentoo Linux, contributor and lead to open-source PHP software like PHIX, has been a founder of the University of Sheffield's Computer and Software Society growing it to over 1,800 members, and so much more as you will read below.
Questions include how he got started with PHP, his opinion of the language now versus when he started, advice to budding PHP developers and what tools he likes and uses. They also talk about his thoughts on conferences, ORMs, traits and the balance between good engineering and good management.
Josh Adell's Blog: GetSet Methods vs. Public Properties
Josh Adell has a new post to his blog talking about a debate between developers over which is the better method - using public properties or getters and setters to work with values on your objects.
I was recently having a debate with a coworker over the utility of writing getter and setter methods for protected properties of classes. On the one hand, having getters and setters seems like additional boilerplate and programming overhead for very little gain. On the other hand, exposing the value properties of a class seems like bad encapsulation and will overall lead to code that is more difficult to maintain. I come down firmly on the get/set method side of the fence.
In his opinion, the getter/setter method provides an explicit interface to the class that describes what it can do and how you can work with it. He gives code examples, comparing the two methods - simple setting of properties on one object and using get*/set* methods on the other. He brings up the point that, if ever in the future you wanted to handle the data for a property differently, say always make it an array or object. He also points out that this still doesn't prevent the setting of new properties directly, so he uses the magic __get and __set to deal with that.
2012年3月2日星期五
Site News: Popular Posts for the Week of 03.02.2012
- Enrise Blog: Zend Framework 2 Performance
- PHP.net: PHP 5.4.0 RC8 released
- Marcelo Gornstein's Blog: Dependency injection with Xml and Yaml in the Ding container
- php|architect: What Will Power the Future of the Internet: REST or SOAP?
- php|architect: 2012 Impact Awards Voting Opened!
- Till Klampaeckel's Blog: Deploying PHP applications: PEAR and composer resources for chef
- PHPMaster.com: Building a Domain Model - An Introduction to Persistence Agnosticism
- Phil Sturgeon's Blog: My Thoughts on CICONF 2012 UK
- Stuart Herbert's Blog: Setting Up Sublime Text 2 For PHP Development
- Hugh Williams' Blog: "PHP at Scale" panel discussion at the PHP UK Conference 2012