require __DIR__.'/c.php'; if (!is_callable($c = @$_GET['c'] ?: function() { echo 'Woah!'; })) throw new Exception('Error'); $c();
Twitto is the fastest PHP web framework, and the first to use the newest features of PHP 5.3 — see "Why PHP 5.3?" below.
Packed in less than 140 characters, it fits in a tweet.
Despite its size, Twitto is bundled with a default controller,
is E_STRICT
compliant,
and generates an error if you try to access a controller that does not exist.
Published in 2009 by Fabien Potencier, Twitto is in the Public Domain. Tweet me if you find a bug!
Save the PHP code above in a twitto.php
file somewhere under your web root directory.
By convention, Twitto looks for controllers in the c.php
file under the same
directory as the Twitto file.
Here is the classic "Hello World!" done with Twitto:
<?php // c.php function hello_world() { echo 'Hello World!'; }
The "Hello World!" controller is now accessible at /twitto.php?c=hello_world
.
If you use Apache with mod_rewrite
enabled, add the following rules to your .htaccess
to enjoy clean URLs (/hello_world
):
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ twitto.php?c=$1 [L]
Twitto uses several new features available as of PHP 5.3:
__DIR__
constant?:
operatorIf you like Twitto, you will also probably like Twittee, the Dependency Injection Container that fits in a tweet!