Extending PHP 5.3 Closures with Serialization and Reflection

PHP 5.3 has brought with it some powerful and much-needed features like late static bindings, namespaces, and closures (also referred to as anonymous functions and lambda functions). Anyone who is experienced with JavaScript or who has worked with programming languages like Scheme or Lisp should realize the value that anonymous functions can bring to PHP. The PHP Manual explains closures like this:

Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses. Closures can also be used as the values of variables; PHP automatically converts such expressions into instances of the Closure internal class.

PHP has very few predefined classes that are part of the core language, so naturally I was intrigued by the Closure class. The PHP Manual has this to say about the class:

The predefined final class Closure was introduced in PHP 5.3.0. It is used for internal implementation of anonymous functions. The class has a constructor forbidding the manual creation of the object (issues E_RECOVERABLE_ERROR) and the __invoke() method with the calling magic.

The invoke magic method is also a new feature in PHP 5.3. It is called when an object is used in the context of a function (e.g. $object($parameter);). Since Closure objects will be used like functions, this is a critical feature of the Closure object. The Closure class may be perfectly equipped to act like an anonymous function, but it does not provide any extra utility beyond that. A var_dump() of a closure will reveal the functions parameters, but there is no way to get any other information about the Closure (like the actual code of the function). Trying to serialize the Closure throws an Exception and json_encode() just returns an empty JSON string. To make matters worse, the Closure class is final, so there is no way to extend it.

That simply wasn’t going to cut it for me. I wanted to make my own Closure class that was at least able to do the following: Read More »

Posted in: Articles, Development

Facebook vs. Twitter Clickthroughs: More Bang For Your Buck

Facebook vs Twitter

While managing your social networking presence on Twitter and Facebook, it can be difficult to quantify the impact of each medium. While I’m a huge fan of Twitter, traffic results from earlier today on one of my sites confirmed for me what may sound like common sense: Facebook fans drive far more traffic per-user than Twitter followers for a given promotional message.

I’m currently running a contest in association with T-shirt company Threadless. (It’s called Threadknits, and it’s based on knitting and crocheting their t-shirt designs into crafts.) Today, Threadless posted a message on their Facebook page and  Twitter, both with essentially the same content: an invitation to check out Threadknits. They were both posted at nearly the same time.

The numbers are what might surprise you. Threadless has almost 1,500,000 followers on Twitter, and “only” 102,000 fans on Facebook. With the posts made within an hour of each other, my traffic on the site shot up, with a couple thousand visitors hitting by day’s end. Here’s the breakdown of traffic driven from each:

Medium: Fans: Visitors: % Audience Clickthroughs:
Facebook ~102,000 ~1,110 ~1.08%
Twitter ~1,490,000 ~682 ~0.04%

 
The difference is absolutely staggering. Whereas Facebook generated an approximate 1.08% clickthrough rate, Twitter’s was closer to, well, 0%. 232 visitors came from Twitter or related sites directly and 450 additional clicks landed on the home page without a referrer, which I’m chalking up to clicks from Twitter clients. (Though, to be fair, this could easily overstate Twitter’s influence.)

On a previous contest, Threadless would tweet and I’d see between 1,000-2,000 clicks on their roughly 1.4 million followers, so while it may be a bit low today, I think the point stands: Even at its best, Twitter for large audiences generates clickthrough rates dramatically lower than Facebook. For 2,000 clicks, the rate at 1.4M followers stood at 0.14%. A quick look at the bit.ly stats on a few links from Ashton Kutcher (the #1 Twitter personality by followers) shows they typically net about 20,000-30,000 clickthroughs, on 4.3M followers, gaining a decent amount on the Threadless best-case scenario all the way up to 0.48% ~ 0.60%. (This accounts somewhat for the viral nature of Twitter as bit.ly clicks are counted for retweets as well.) Naturally, clickthrough rates will vary dramatically even amongst popular Twitter personalities for a variety of reasons. I’d like to focus more on the significant difference between the Facebook and Twitter rates I witnessed today.

There are likely several possible reasons for this:

  • The audience may be slightly different—people willing to consider themselves “fans” on Facebook may be more picky with their allegiance than those willing to follow an account on Twitter.
  • The phrasing and formatting of the message were slightly different—not exactly apples-to-apples as Facebook includes the logo and a text clip from the website, but I imagine this had a negligible effect.
  • My mileage may vary—this is an admittedly small sample size, but I think the evidence and logic around these results indicate they’re not anomalous.
  • Most importantly, Facebook lingers while Twitter sails by. Users are probably more likely to follow links during their Facebook time than from a passing Twitter notification unless it’s of particular interest to them.

That last point is particularly important. Facebook, having reconfigured their News Feed yet again, no longer sorts things there chronologically. They’ve merged the Highlights functionality back into the News Feed which they now use to keep certain posts “stickier” than others based on what they believe you might be interested in. (It manages to do a strikingly horrible job at this compared to how it used to perform, but that’s a conversation for a different post.)

With Twitter, the very nature of real-time can be summed up: blink and you miss it. While you can use a Twitter client to review tweets over the past day or two, it’s still less likely your tweet was as visible over Twitter as a post would be on Facebook’s News Feed. I’d like to see some more statistics on total audience reach. The clickthrough rate surely only tells part of the story—I’d be far more interested to learn what percentage of each audience even saw the post, and determine true clickthrough rates from that.

In the end, it’s important to consider the overall spirit of the findings here. Twitter is great for growing virally and interacting with customers, but your message on Facebook may have a far more lasting impression and generate greater returns, even if fans are more of a fight to procure. Engage on both, but recognize the differences between them and leverage each of their strengths. I’ll likely post about the best way to do that for each site in the near future.

(The above graphic represents the total clickthrough breakdown by medium assuming a linear progression of Threadless’ Facebook audience to match their Twitter audience, maintaining the same clickthrough rates from today’s traffic. It’s likely the Facebook clickthrough rate could in fact fall some as their audience grew, but it’s my belief that it would still beat Twitter, user for user.)

Posted in: Articles, Cool Stuff

Nexus One Subsidy Hack: Drop Your Data Plan, Get $100

nexus_oneGoogle officially released their Nexus One Android phone today under the guise of a $179 subsidized price tag ($529 unsubsidized and unlocked). As many T-Mobile customers discovered today, that price only applied if you weren’t already a loyal customer. Instead, TMO customers were shafted subsidized based on their contract status and the presence of an existing data plan.

The official Google Support page describes the following subsidy tiers:

  • Nexus One without service: $529
  • Nexus One with new, 2-year T-Mobile US service plan for new customers: $179
  • Nexus One with new, 2-year T-Mobile US service plan for qualifying existing T-Mobile customers who are adding data plans: $279
  • Nexus One with new, 2-year T-Mobile US service plan for qualifying existing T-Mobile customers who are upgrading their data plans: $379

I’ve been a T-Mobile customer for a little over seven years now, and off-contract for pretty much that entire time. I’m thus now open to what T-Mobile calls their full subsidy. Except with the Google phone, where Google manages the subsidy, not T-Mobile. Since I had a $10/month sad, EDGE-based data plan with TMO, Google informed me after polling the TMO servers that I was eligible for the $150 subsidy, for a Nexus One price of $379. The next subsidy tier up is $100 cheaper for a price of $279.

The only distinction lies in whether you are “upgrading your data plan” or “adding a data plan.” This seemed like a simple enough problem to fix: I called T-Mobile support and asked them to cancel my data plan. They said it would be no problem, since I’m not under contract. I worried briefly that it wouldn’t be visible to the Google-based powers that be until the next billing cycle, but the TMO rep informed me that the change is instant. Since I knew I was buying a Nexus either way, I pulled the trigger.

Wouldn’t you know it, not five minutes later when I went to make the purchase again Google’s web store fetched my data and lo and behold, my Nexus price was now just $279. Easy-peasy, that.

The ironic part is that I’m moderately sure I could re-activate the data plan now without incurring any real additional fees in the day-and-a-half I may have to wait for the overnight shipping to get here, but I don’t use the slow EDGE service enough to warrant wrecking my cool here.

After all the dust settled, I realized how asinine Google had decided to make the checkout process by managing sales and subsidies of the device themselves. They limit you to just one rate plan during your purchase, which is more than a little infuriating as I received different answers from TMO reps over whether upping my minutes would cause Google to come after me for the subsidy. (It appears that you CAN upgrade your account to another Even More plan according to a recently-added note on this Google Support page.) The pricing rates are buried under a Support knowledge base article and not at all transparent. Google says $179 and then pulls an enormous J/K on you as they fetch your account information, seemingly pulling a figure out of thin air as it suits them. The T-Mobile reps can’t do anything about it since the purchase isn’t on their side of the pond at all. And Google is nowhere to be found.

Strange to me that a company so intent on delivering a device with their brand and full-throated support would instantly fawn off users to HTC and T-Mobile so that they don’t need to support their customers in any meaningful way. This isn’t the first time Google has proved shockingly absent with matters of support, but it feels very different when you’re purchasing a product subject to additional cancellation fees.

Further, it seems completely short-sighted to limit the subsidy as they have. Restricting the best price to new T-Mobile customers alone is frustrating, but they make it nearly impossible for anyone with a family plan to switch at the subsidized price. Worse, the subsidy at its lower rates really just amortizes the cost of the phone out over those two years, as the Even More plans cost $10/month more—that’s $240 over two years right there. Let’s be clear: At $379, you’re better off financially buying the unlocked phone and using the Even More Plus plan, which costs $10 less, for a total savings of $90 over the two year term. Even better since you’re not under any contract at the $529 rate.

Creating barriers to entry for new customers is always a bad idea, made all the worse when those barriers seem arbitrary and class-based. Google needs to stop with the silly tiers and subsidize the damn phone like they’re usually subsidized through carriers. They should allow purchases under family plans and not take the data plan into account. And they should allow you to select from any of T-Mobile’s Even More tiers, which would save me a phone call with T-Mobile’s (admittedly friendly and typically knowledgeable) support.

[1/18/2010 Edit: It was reported last week that Google is nixing the $379 rate entirely, so existing T-Mobile subscribers of all (out-of-contract) stripes will now qualify for the $279 offer. Early adopters who got hit with the $379 rate will have a refund check sent to them. Good on Google, but it'd be nice if it were $179 for all.]

Posted in: Rants, Tech News