Version: v0.5.1 - Beta.  We welcome contributors & feedback.  THanks!
THT Hypertext Toolkit
THT is a web development language
that transpiles to PHP.
THT completely revamps the usability of PHP and
builds in security best practices.

How It Works 

When you add or update a .tht file, it is automatically transpiled to PHP on the first request. It is then cached for performance.

There are no build steps, background tasks, or server restarts to disrupt your flow. Just save and refresh.

The transpiled code is compatible with PHP v5.6+. However, PHP 7.1+ is recommended.

The transpiler itself is written in 100% PHP with no dependencies.

Third-party PHP libraries can be accessed through the PHP Interface.

Why PHP? (The Good Parts)

PHP has a lot of basic usability flaws.

However, it also has a few unique advantages that has made it one of the most popular languages in the world.

THT keeps the good parts of PHP:

Easy Setup
PHP is available on every major web host and OS. Using it with Apache is fast out of the box, with virtually no system administration.
Simple Routes
In PHP, every file has a URL. THT automatically provides clean URLs (e.g. "/myBlog.tht" becomes "/my-blog"), and blocks access to private code.
Atomic Requests
State and data are automatically cleaned up after every request. This "share nothing" approach enables horizontal scaling and simplifies your app flow.
Web Focused
PHP is a web language at its core. THT embraces this even further by building in web security and framework features.
Batteries Included
PHP comes with a massive library of convenient functions. THT completely re-organizes this library and makes it more consistent.

A Quick Look 

THT uses a more modern JavaScript-like syntax, with additional shortcuts and safeguards.

This similarity to JS makes it more accessible as a general tool for all web developers.

// Variables are pre-declared.
let colors = ['red', 'blue'];

// Built-in types have methods.
colors.push('yellow');

// The standard library is organized into modules.
Response.sendPage({
    title: 'Primary Colors',
    body: bodyHtml(colors),
});

// Template functions let you separate and
// organize your output/views however you like.
// (e.g. by component, module, file, etc.)
template bodyHtml(colors) {

    <h1>Primary Colors</>
    <ul>
    -- for (color in colors) {
        <li>{{ color.toUpperCase() }}</>
    -- }
    </>
}

Key Features 

Here are some of the biggest improvements that THT provides:

  • Organized Library. PHP's massive library (5,000+ functions) is curated and organized into modules & classes.
  • Lists & Maps. PHP arrays are split into clear List and Map types.
  • Module System. File inclusion is supported via modules with built-in autoloading. No verbose namespaces.
  • Friendly Errors. The error pages are designed to be easy to read, with full stack traces.
  • Syntax Shortcuts. Optional syntactic sugar makes common patterns more convenient. (e.g. ||= for default assignment.)
  • Cleaner Code. A compile-time format checker helps you write code that is easier to read and maintain.
  • UTF-8 Support. String functions work with UTF-8 by default.

Web Framework Included 

THT includes many tools that are useful for modern web development:

Built-In Security 

By default, THT defends against the most common security risks, so you can spend more time building the functionality of your app.

Because these are integrated into the language itself, they provide better protection than if they were imported from a third-party library.

Performance 

Out of the box, PHP is more than fast enough for most apps.

PHP 7 already offers major speed gains, but you can benefit even more by using an opcode cache like APC.

On a MacBook Pro, the core THT test suite (770 tests) finishes in 18 milliseconds. This includes a full range of operations for control flow, data structures, file access, and database access.

Compared to the most popular PHP packages, THT is a safe choice, performance-wise:

In a basic “Hello World” benchmark, THT is 6x faster than Laravel (1000 req/s vs 160 req/s) and uses 60% less memory (0.8 MB vs 2 MB).

The THT bundle is about 80x smaller than Laravel and its dependencies (180 KB vs 16 MB, zipped).

It also has built-in performance tools:

Give It a Try 

THT is still in Beta, but if you’d like to try it out, it’s already suitable for most small-to-medium web apps.