Welcome

Welcome to the documentation of the THP programming languague.

THP is will be a new programming language that compiles to PHP.

Accurate visual description of THP

Compiler rewrite

THP was previously written on Rust, but now it’s being rewritten in Zig.

Friendship ended with Rust, now Zig is my best friend.

Due to the rewrite everything has reversed. The Rust version was v0.1.3, the Zig rewrite is v0.0.1. Also, this is a good opportunity to version the docs.

The latest branch contains future ideas and stuff, but the versioned branches (for example, v0.0.1) will document only actual, implemented things, and new branches will be published as the compiler evolves.

Why?

PHP is an old language. It has been growing since 1995, adopting a lot of features from many places like C, Perl, Java, etc. This was done in a very inconsistent way, as detailed by Eevee in their article PHP: a fractal of bad design.

Along the years PHP has been improving. PHP added classes, exceptions, interfaces, traits, type hints and checks, functional features, reflection, etc., etc. However, by building on top of the existing language without a clear design philosophy, and by keeping backwards compatibility, we ended up with a messy language. The article above goes into detail about this.

In spite of this, PHP has remained widely used and loved, in a weird way (I’d say in the same way that people love JavaScript), and at the time of writing PHP 8.3 is available. However, PHP is to my eyes fundamentally flawed, and cannot be fixed without completely breaking what came before.

This is where THP comes in. I wanted a modern language that could run in the same environment that PHP does. And I quickly realized that building on top of PHP in the same way that TypeScript did for JavaScript would be detrimental. It would be better to create a completely new language, treat PHP source code as a “low level” compilation target, and focus entirely on the new language.

This new language would be mainly inspired by what I consider the best designed languages out there: Rust as a baseline, Zig for its null and error handling and Kotlin for its OOP features. In a way, PHP will be adapted to, say, Rust’s syntax and semantics, instead of having Rust adapt to PHP.

In pursue of this THP will ditch many things about PHP, in name of consistency. These are things that PHP devs are used to doing, but that I consider bad practices, hacks or workarounds. One example of this are variable variables on PHP: $$variable.

Another critical point of THP is type safety. It is a goal to approach the same level of type safety that have compiled languages like Java/Go/Rust, and leave aside dynamic typing as much as possible. Types cannot be turned off, you cannot use Any to avoid typechecking, and so on.

Finally, there are some additions to the language that I consider essential today: A good, unified LSP, type definitions, accesible documentation, an opinionated code formatter and plugins for major editors like VSCode and Neovim.

Goals

Not goals

These are not things that THP wants to solve or implement

THP intentionally uses a different syntax from PHP to signal that it is a different language, and has different semantics.