Core\DeprecatedError
The error a use of deprecated code throws when the setting errors.deprecated is throw. Code is deprecated when it carries the attribute #[Core\Deprecated]. The error is a LogicError, because the program itself still uses old code.
By default the setting is ignore, and deprecated code runs as usual. Set it to throw while you test, and every use of old code stops with this error. Its message names the method or constant, the version that deprecated it, and the code to use instead when the attribute names one.
A program can change the setting for its own request with Core\Config::set('errors.deprecated', 'throw'). The change applies to that request only. The next request starts with the setting from nvs.toml again.
The example below shows a test run that finds a call to an old method and prints what to use instead.
Examples
Finding old code while you test
<?nvs// Shows how to find calls to deprecated code while you test a program.
class Cart{ #[Core\Deprecated(since: '2.0', replace: 'Cart::total($prices)')] public static function sum(array<int> $prices): int { return Cart::total($prices); }
public static function total(array<int> $prices): int { int $result = 0; foreach ($prices as int $price) { $result = $result + $price; } return $result; }}
// The setting is `ignore` here, so the old method runs. This prints 12.echo Cart::sum([5, 7]), "\n";
// With `throw`, each use of deprecated code throws `Core\DeprecatedError`.Core\Config::set('errors.deprecated', 'throw');try { echo Cart::sum([5, 7]), "\n";} catch (Core\DeprecatedError $old) { echo $old->message, "\n";}
// `total` is not deprecated, so it still runs. This prints 12.echo Cart::total([5, 7]), "\n";12`Cart::sum()` is deprecated since 2.0. Use `Cart::total($prices)` instead.12