A modern, consistent typed language for PHP.
thp keeps track of the datatype of all variables, and allows you to have complex types and type inference.
type Person = { String name, String lastName, Int age, } Option[Array[Person]] persons = PersonManager::getAll() print("There are {persons?.length ?? 0} persons registered!")
thp groups all global variables and function of PHP into modules,
to allow easy access and organization.
Function names, parameters and return types are improved, and you
can treat primitive types as objects.
val name = "John Doe" val lastNamePos = name.indexOf("Doe") // Instead of `strpos` val letters = name.split("") // Instead of `str_split` or `explode` val notALetters = letters.filter { $ != "a" } // Instead of `array_filter`
All null values must be explicitly marked and handled,
avoiding many errors, via the Option
ADT.
Also, functions that return false
as
an error state now return an Option
,
and exceptions return a Result
instead.
val allowedColors = Array("red", "blue", "green") val response = match colors.search("purple") { Some(_) -> "purple is allowed!" None -> "purple is not allowed" } print(response)
use PDO use Globals::Env val #(Some(dbUri), Some(dbUser), Some(dbPassword)) = #( Env::get("DB_URI"), Env::get("DB_USERNAME"), Env::get("DB_PASSWORD"), ) else { die("All 3 db environment variables must be set.") } match PDO(dbUri, dbUser, dbPassword) { Ok(connection) -> { /* db operations */ } Err(pdoException) -> { /* handle exception */ } }