PHP in a Tweet

Yesterday an ex colleague tweeted something that captured my attention:

So I started thinking to a Twitter-powered code golfing competition. Looking for other examples you can see these:

This is Twittee: a dependency injection container in a tweet.

This is Twitto: a web framework!

And this is a microframework created on the occasion of this “competition”. It’s called μ and you can find its documentation here.

These are three really nice examples of PHP code in a tweet. Of course you can’t use these two snippets in production, but you can see that a short script isn’t always an useless script or something prosy.

I realized the next two examples and would be great to see your tweets too!

This is a function used to bypass the array_intersect note “Note: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.”

Using this you can check if a request is made using AJAX or is a simple web-client request. I think this could be a nice game (and a personal test) for each PHP developer.

Game rules

  1. The tweet have to be a well-formed PHP code. You can check the right syntax using php -l tweet.php as described here: php.net/manual/en/function.php-check-syntax.php
  2. A code is taggable only using things like echo "#php"; or return "#error"; but still keeping your tweet a well-formed PHP code
  3. Open (<? and <?php) and close (?>) tags are not recommended

If you want suggest a ranking algorithm/formula, new rules or suggest methods to write the code, comment down here. For example you can evaluate comments, or the usage of some methods and classes, or evaluate more retweets than number of users that favorites your tweet, more the length or the utility, etc… I would be glad to see your tweets, so comment here linking your tweets!

Update of 27/08/2015

As you can see from the tweet below, this code golf game seems to be still alive, what about something more than a blog post?

Leave a comment and we can discuss about it, I think that something like 140byt.es or something more complex could be funny, and you? :)

Old discussion on Hacker News