Coming from PHP
This page is for you if you already know PHP. Novis looks like PHP, but it is a different language. PHP code does not run in Novis.
The short list
The ten most important differences between PHP and Novis.
Every variable, parameter and property declares its type once, and a value never changes its type. Every function is a method of a class, and every constant belongs to a class. Novis has no global variables, so $_GET and global do not exist. The Core classes are the standard library, and a method that fails throws an error.
== never converts its operands, and === does not exist. A string is UTF-8 text, and binary data has the type bytes. The keys of an array are always strings. Novis has no eval, no references and no magic methods.
Tasks and channels for work that runs at the same time are built in. A program needs a permission in nvs.toml to read a file or to open a network connection. Tests are part of the language, and nvs test runs them.
A stock count
<?nvs// Shows a short program as a PHP developer would write it in Novis.
// A function is a static method, and a constant belongs to a class.class Stock{ public const string UNIT = 'pcs';
public static function total(array<int> $counts): int { int $sum = 0; foreach ($counts as int $count) { $sum += $count; } return $sum; }}
// Every variable has a type. This prints `17 pcs`.array<int> $counts = ['apples' => 12, 'pears' => 5];echo Stock::total($counts), ' ', Stock::UNIT, "\n";
// `==` does not convert its values. "12" and "012" are different strings, so this prints `no`.echo '12' == '012' ? 'yes' : 'no', "\n";
// `as int` converts the string to a number first. Now both sides are 12, so this prints `yes`.string $input = '012';echo ($input as int) == $counts['apples'] ? 'yes' : 'no', "\n";
// A string counts characters the way a person sees them. This prints `4`.echo Core\Str::length('Café'), "\n";17 pcsnoyes4Porting a program
To port a PHP program, you read it to learn what it does, and then you write it again in Novis.
PHP code does not run in Novis, and no tool converts it. There is also no list that gives the Novis method for each PHP function. You choose the new design yourself.
Start with the types: the classes, their typed properties and the enums. Then write each part again with the Core classes. nvs agent find finds the method for a task. Run nvs check after each part, and write tests that nvs test runs.
For a large program, an AI coding agent can do this work. nvs agent init tells the agent about nvs agent, and the agent looks up each method with nvs agent find and nvs agent show.
An invoice moved from php
<?nvs// Shows a small invoice program from PHP, written again in Novis.
// The constructor is named `constructor`. `public` on a parameter also declares a property.class Line{ public function constructor(public string $product, public int $quantity, public int $price) {}
public function total(): int { return $this->quantity * $this->price; }}
// A function is always a method of a class. A constant is always a constant of a class.class Invoice{ public const int FREE_SHIPPING = 100;
// `array<Line>` is an array that contains only `Line` objects. public static function total(array<Line> $lines): int { int $sum = 0; foreach ($lines as Line $line) { $sum += $line->total(); } return $sum; }}
// `as int` converts a text to a whole number. The text is "3", so `$quantity` is 3.string $typed = '3';int $quantity = $typed as int;
array<Line> $lines = [new Line('pen', $quantity, 20), new Line('notebook', 1, 45)];int $total = Invoice::total($lines);
// `&&` is the only way to write "and". This prints "105 free shipping".echo $total, ' ', ($total >= Invoice::FREE_SHIPPING && $quantity > 0) ? 'free shipping' : 'plus shipping', "\n";
// `$paid` is a text, so `as int` converts it before `==` compares it with `$total`. This prints "paid".string $paid = '105';echo $paid as int == $total ? 'paid' : 'open', "\n";
// `as int` throws an error for a text that is not a number. This prints "not a number".string $wrong = 'three';try { echo $wrong as int, "\n";} catch (Throwable $notANumber) { echo "not a number\n";}105 free shippingpaidnot a numberThe tools you do not install
Novis has the work of PHP's common development tools built in, so you install none of them.
Tests replace PHPUnit. A test is a method with the #[Test] attribute, Core\Test has the assertions, and nvs test runs the tests. Data rows, a skip with a reason, retries, and JUnit and JSON reports are included.
nvs check replaces PHPStan and Psalm. It is the compiler. It checks that every variable has a type, every method exists, every path returns a value and every property is initialized. It also checks where untrusted input (tainted) and secret values (secret) are used. It has no levels and no baseline file.
The style rules that find bugs are compile errors, and this replaces PHP CS Fixer and PHP_CodeSniffer. The compiler checks the case of every name and the visibility of every method, property and constant. You configure nothing.
A price with its tests
<?nvs// Shows a program and its tests in one file, with no test framework to install.// `nvs run` runs the program. `nvs test` runs the methods that have `#[Test]`.use Core\Test;use Core\Test\TestWith;
final class Price{ // Adds a tax in percent to a price in cents. public static function withTax(int $cents, int $percent): int { return $cents + Core\Math::quotient($cents * $percent, 100); }}
final class PriceTest{ // Each `#[TestWith]` line is one test with its own values. `nvs test` reports three tests. #[TestWith(cents: 1000, percent: 20, want: 1200)] #[TestWith(cents: 999, percent: 10, want: 1098)] #[TestWith(cents: 0, percent: 20, want: 0)] #[Test] public function taxIsAdded(int $cents, int $percent, int $want): void { Test::assertSame(Price::withTax($cents, $percent), $want); }
// `skip:` needs a reason. `nvs test` does not run this test, and it prints the reason. #[Test(skip: 'refunds are not written yet')] public function aRefundGivesTheTaxBack(): void { Test::assertSame(Price::withTax(-1000, 20), -1200); }}
// `nvs run` starts here. This prints 1200.echo Price::withTax(1000, 20), "\n";
// `Core\Test::assertSame` is a normal method, so `nvs run` can call it too.// 1098 is not 1099, so it throws `Core\Test\Failure`. This prints the message of that error.try { Test::assertSame(Price::withTax(999, 10), 1099);} catch (Core\Test\Failure $failure) { echo $failure->message, "\n";}1200Core\Test::assertSame failed: `$actual` is 1098, `$expected` is 1099