PHP Namespaces 5

Posted by Nick Ashley on October 26, 2008

I have been seeing alot of complaining lately regarding PHP namespaces, and I thought I would chime in with my (often opposing) views. First off, let me explain the issue.

The new version of PHP will have a new feature, called namespaces. (I wrote about it in my post”PHP 5.3 Feature Preview“. This is a great featured, and one that the community as a whole is excited about. So what is the problem, then?

Well initially PHP was going to use the standard “::” syntax to invoke the namespace. For example:


namespace Foo;
   function bar() {
      echo "Namespace Foo";
   }
   Foo::bar();

However, this became a problem for the parsing engine, as it is the same way to call a static function.

class Foo{
   static function bar(){
      echo "Class Foo";
   }
}
Foo::bar();

So instead, PHP changed the syntax to a blackslash. So now, in the first example, you have ‘Foo\bar();’ while in the second, you still have ‘Foo::bar();’ Seems reasonable to me (and the PHP core members) but not to some.

For example, Ninh complains on his blog that if you put the invocation in double quotes, it will interpret things like “\t” as a tab, and that you have to use 2 backslashes. I really don’t see this being a problem. First off, why on earth would you use double quotes? There are no variables or single quotes being used in the string, so one should be using single quotes anyways. That is just good programming practice.

Even if you do use double quotes, there is a tried and true, standard solution to escape the backslash character. It is so obiquitous, that Ninh didn’t have to learn how to use it, he already knew about it, yet is still complaining. His problem with this method? “It looks like crap”. I’m sorry, I though we were using logic to code web applications, not painting a picture. And even at that, why does “::” look awesome, but “\\” look like crap? I don’t get it.

My favorite quote if from the very end of his post. He claims “Last time I checked, the world wasn’t filled with scrawny developers that would come crying to their mommies after getting their first facepalm of ‘AmbiguousInvocationError’.” And yet he is crying to his mommy (or rather, the blogosphere) because if he uses double quotes (which he doesn’t have to) then he has to escape the backslash character (a standard practice) and that’s “ugly”.

So what are your thoughts? Maybe I’m crazy, and this is a huge deal. I just don’t see it.

Google adds ‘Suggest’ feature to homepage

Posted by Nick Ashley on August 30, 2008

Google suggest is a handy feature that displays a list of likely search terms as you are typing them. This feature is usefull for several reasons:

  1. It often stops you from having to type your entire search phrase in
  2. It’s a quick way to check the spelling on a word
  3. It gives you an idea of what a good search phrase is that is related to what your after

This feature has been around in google labs for awhile. A form of it is also used in the search bar of firefox (although the search bar only displays phrases, and not the number of results each will return). So the feature itself isn’t new, but making it the default on the homepage for all users (even guests) is a big deal.

I think it is a good move. Of course they want their homepage lite and responsive, but I believe the functionality is worth the extra pageload. Beside, an Ajax search like this really doesn’t take much javascript when done right. In fact, I recently implemented a similar feature for searching tags on able2know.

I implemented it without the help of javascript libraries, although I do have a javascript file I’ve written that contains a small set of usefull tools, such as targeting elements, sending ajax requests, or validating json data. Using these helper functions, my search code becomes this simple:


var tagSearch = {
	init : function(){
		tagSearch.e = $('tagSearch');
		tagSearch.resultBox = $('tagSearchResults');
		tagSearch.original = tagSearch.resultBox.innerHTML;
		tagSearch.e.onkeyup = function(e){
			if(tagSearch.e.value != tagSearch.lastValue){
				tagSearch.lastValue = tagSearch.e.value;
				if(tagSearch.e.value.length > 1)
					Ajax.get('/rpc/tag/search/?s=' + tagSearch.lastValue, null, tagSearch.update);
				else if(tagSearch.e.value.length == 0)
					tagSearch.resultBox.innerHTML = tagSearch.original;
			}
		}
	},
	update : function(r){
		var data = JSON.parse(r.responseText);
		if(data.html){
			tagSearch.resultBox.innerHTML = data.html;
		}
	}
}

On the php side of things, I am returning html to keep things simple. Pretty easy, eh?

Able2know launches

Posted by Robert Gentel on August 25, 2008

Able2know has long run an experts exchange on phpbb, but has recently launched a new custom software to replace the old forums. This software was developed by two of us Agile Webmasters (Nick Ashley and myself) over the course of the last 10 months or so and while we launched quite rough it’s been evolving quickly in the days since and we are committed to making it a very rich and usable web application.

Over the course of the next weeks we’ll talk about our development process and decisions to give advice to others facing similar challenges but you are welcome to ask us questions about web development on able2know anytime.

The essential Firefox Plugins for the Web Developer

Posted by Robert Gentel on August 15, 2008

Nick has already posted about Firebug and Firebug Extensions and in my own experience in setting up my workstation I too found this to be an essential Firefox Add on. In addtion to Firebug, here are the other Firefox plugins I’ve already installed in my first few days of work on this new computer.

  • Delicious - An agile webmaster might know thousands of online resouces and having them on one computer in the form of browser book marks is not very agile is it? Using delicious you can take your bookmarks with you, and this was one of the first things I missed having: all my bookmarks.
  • SearchStatus - This plugin is essential for the SEO professional. It gives you Google pagerank, Alexa Rank and Compete rank information for the websites you visit and also has a useful keyword density analyzer and quick access to searches to find indexed pages, backlinks and cache. It’s one of the tools I use the most when investigating a website.
  • Web Developer Toolbar - While this was originally a must-have tool for its live css editing, Firebug has become much more useful for that purpose. But this tool is still very useful for a variety of other information and I also tend to use it a lot to quickly disable cache, cookies, or JavaScript.
  • ColorZilla - This gives you an easy color picker and an eyedropper that can be used to quickly get the color of anything on any webpage.
  • And of course, Firebug and YSlow as Nick has already blogged about.

Useful Software for the Agile Developer

Posted by Nick Ashley on August 14, 2008

Robert’s recent post setting up an agile webmaster workstation got me thinking about what software I utilize as an agile webmaster. While I agree (mostly) with his list, I have a few additions and alternatives.

Browsers

I agree with Robert’s list here wholeheartedly. (for those just tuning in, Robert recommends installing the lastest Firefox, Opera, and Safari browsers. He also has both IE6 and 7 installed). I would just like to expand on the IE bit. Microsoft does not allow you to have both versions of internet explorer installed at the same time, so a workaround is needed. I prefer using software called Multiple IE by Tredosoft. It uses DLL redirection to allow you to install as many versions of IE as you want (from 3.0 to 6.0!)

Development Tools

  • Zend Studio - I spend most of my time developing PHP, and as such I find Zend Studio to be a godsend. It is not free software, but the Standard Version can be had for $99, and provides all basic functionality. With this software, you never had to worry about misspelled variables, forgotten semi-colons, or the order of arguments for a function ever again. If you are a PHP developer who hasn’t used it, download the trial, you’re in for a treat.
  • PSPad - when I coding in a language other then PHP, or I just need to make a quick edit, I prefer PSPad. It is an excellent piece of freeware that has some powerful built in text manipulation tools, all with keyboard shortcuts. It also allows you to record your own macros, and play them back in a variety of ways. This has saved me countless hours when doing monkey work.
  • SQL Yog - PHP and Mysql kinda go hand in hand, so I spend a decent amount of time writing mySQL queries. SQL Yog is an excellent desktop application to manage mySQL databases. Its like a desktop version of phpMyAdmin, which is very handy.

FTP

  • Smart FTP - This is my favorite FTP software, for one killer feature: It allows you to lock the local directory to the remote directory, so when you open a folder on one side, it opens on the other side. This is very handy for keeping your local file structure the same as remote. It also supports live editing, server to server transfers, and everything else you would expect. Its only downside is its not free. However, it is reasonably priced at $37 - $50 for a single user.
  • FileZilla - If you don’t feel the need to pay money for an FTP solution, then you probably want to be using FileZilla. FileZilla is a free client, and is a great implementation of all the standard features you’d expect.

Other Utilities

  • KeePass - Most web developers have many many passwords to remember. Also, most web developers are smart enough to realize good passwords contain special chars, and are generally hard to remember. These 2 facts make password managers very useful. Keepass is my favorite. It stores all passwords in a safe, encrypted file. Then you just have to remember one ‘master’ password to unlock the application, where you can double click an entry to automatically copy the password to your clipboard. It allows you to easily categorize your passwords, store notes, search, etc. Also, it is a standalone app which will run from a USB key, so you can take your passwords with you, but they are safe if the usb key is lost or stolen.
  • Open Office - Robert mentioned cases when clients send you word documents, and you need something to open them. Google Docs is great, but is no replacement for a desktop app. However, I have found that Open Office fulfills all my needs. Admittedly, I use it very rarely. However, I have yet to run into an office file it couldn’t open, and yet to have a client complain that they couldn’t open a file I saved. There hasn’t been much talk about Open Office recently, as all the hype is moving to web apps. However this is one application that I feel still makes sense as a desktop app, and is a great example of quality open source software.

Yahoo launches Fire Eagle 2

Posted by Robert Gentel on August 13, 2008

Yahoo launched Fire Eagle yesterday, a web service that lets users input their location for use by other web applications. Web developers can use its API to create applications that then use this information to provide location-based services to the user.

The user can input their location through a variety of methods, with the most antiquated being the entry of their location on the Fire Eagle website or even, in the hyper Web 2.0 world, SMS. However it also allows phone-based applications to broadcast the user’s location to the web service which allows for real-time uses of local data that open a lot more application possibilites.

The user has control over what location details are broadcast, but privacy advocates are sure to cringe at the encroaching of the smart cloud that knows more about you, as the initial uses for this are largely related to commercial opportunities in your proximity.

Are you imagining an ad network that serves ads relevant to where your laptop or phone currently is? I am and it’s a frickin’ “Starbucks on the right” banner that I think could wring a few more bucks a day out of those caffeine junkies.

PHP 5.3 Feature Preview 1

Posted by Nick Ashley on August 13, 2008

Earlier this month the PHP development team released an alpha version of the PHP platform (Read the Official Announcement). Of course there are many bug fixes, improvements, and new features. Here is a quick breakdown of the new features I am most excited for:

  • Namespaces - Finally! No longer do you have to worry about variable, function, or class names in the global scope interfering with other code libraries you may be using. A namespace essentially gives you your own personal global namespace, which you get to define. This means if you create a class called ‘user’, you can use someone else’s codebase even if they have a ‘user’ class as well.  Other languages such as C++ have had this feature for years, so its great to finally have it available to PHP. This may convince some that PHP is a viable solution in more huge, enterprise level codebases.
  • Late Static Binding - this is for those hardcore OOP coders. What this allows you to do, is reference an objects type (class name) from a function that is only available via inheritance. Its a confusing concept, but can prove useful in some situations. For a better example, see the Late Static Bindings Manual (procedural programmers need not apply).
  • Lambda Functions and Closures - Lambda functions are essentially anonymous, throw away functions. They can be useful if you want to use a simple function when you are already inside a function. Without Lambda functions, it would need to be defined elsewhere. However in some cases this can be hard to follow when reading the code, and seems wasteful when you only need to use the function once. A perfect use-case for Lambda functions is when they are defined for callbacks for other functions, such as array_walk(), or preg_replace_callback(). With Lambda functions, you can assign the function to a variable. Javascript programmers will recognize these as anonymous functions, as they are something many javascript programmers use heavily.

These are all very welcome additions, and I can’t wait till the stable version is out. The current roadmap estimates a stable version will be available by mid-October. Kudos, PHP Development team, keep up the good work!

Comscore announces explosive growth in social networking websites

Posted by Robert Gentel on August 12, 2008

Not to be outdone by the other web metrics companies releasing their traffic analysis articles in the last few days, Comscore announced today that “Social Networking Explodes Worldwide“, citing a 25% growth worldwide in the last year.

Naturally, the growth is largely coming outside of North America whose 9% growth rate for the year is the lowest globally and emerging internet markets were responsible for most of the growth.

Additionally, they released information about specific sites showing MySpace nearly stalled at 3% growth with Facebook and Hi5 the fastest growing social networks at the moment. Also of interest to the social media marketer is that they are showing Facebook as having overtaken MySpace in monthly uniques. But then again, only a blind social media marketer wouldn’t have noticed Facebook’s meteoric rise.

Google crosses 70% search market share in US 1

Posted by Robert Gentel on August 12, 2008

Research firms Neilsen Online and Hitwise have released traffic information that shows strong Google growth in the US market. Google’s audience through its variety of web properties grew by a million from June to July to 129 million (Google has the largest audience in the US through its properties like Google.com and YouTube.com). But even more damning for its rivals (namely Microsoft and Yahoo), and arguably for the webmaster community, is the information Hitwise released today about the most coveted traffic of all: search traffic. Hitwise announced that Google has crossed the 70% mark (they cite 70.77%) which is up 10% from July of last year and 2% from June of this year. Here’s the rest of the search landscape that Google dominates:

  • Google - 70.77%
  • Yahoo - 18.65%
  • MSN/Live - 5.36%
  • Ask - 3.53%

And here’s a graph from Hitwise:

Google releases Keyczar open source cryptographic toolkit

Posted by Robert Gentel on August 11, 2008

Google has announced the release of their open source cryptographic toolkit Keyczar. It is a toolkit that Google claims (I have no experience with it yet) will make it easier to do cryptography right.

Keyczar’s key versioning system makes it easy to rotate and revoke keys, without worrying about backward compatibility or making any changes to source code.