Property names as values
Sometimes the name of a property comes from a web address, a form or a JSON body. These three types check that the name is right. A name written in the code is checked when the program compiles.
Property keys
A property key is a value that names one public property of a class.
You use a key when the name of a property is known only while the program runs, such as a sort column from a URL. A value of type property<User> is the name of a public property of User, including inherited ones. as converts a string to a key, and throws an error if the string names no public property. as ?property<User> gives null instead. $user->$key reads or writes the named property.
An attribute is data written above a class or a property, as in #[Search(fields: ['title'])]. When you declare an attribute, a field typed property<static> takes the name of a public property. static is the class the attribute is used in. A wrong name does not compile.
Good to know: a private or protected property never converts to a key. If a class has a public readonly property, no write through a key of that class compiles, whatever property the key names.
The examples below sort a table and update properties by name. Then they show two wrong writes, a key of a parent class on a child object, and an attribute.
Sort a table by a column from the address
<?nvs// Sorts a product table by the column a visitor picks in the web address.
class Product{ public string $name; public int $price; public int $stock;
public function constructor(string $name, int $price, int $stock) { $this->name = $name; $this->price = $price; $this->stock = $stock; }}
array<Product> $products = [ new Product('Lamp', 40, 3), new Product('Chair', 85, 12), new Product('Desk', 120, 1),];
// The address ends with `?sort=price`. `as ?property<Product>` converts "price"// to a property key. A name that is not a public property gives `null`.?property<Product> $picked = Core\Request::queryParameter('sort') as ?property<Product>;
// Without a valid column, the table is sorted by "name".property<Product> $column = $picked ?? 'name' as property<Product>;
// `$product->$column` reads the property that the key names.array<Product> $sorted = Core\Arr::sort($products, { by: fn(Product $product) => $product->$column });foreach ($sorted as Product $product) { echo $product->name, ' ', $product->$column, "\n";}Lamp 40Chair 85Desk 120A function that takes a property name
<?nvs// Shows a function whose parameter accepts a property key or any string.
class User{ public string $name; public string $email; private string $passwordHash = 'x9f2';
public function constructor(string $name, string $email) { $this->name = $name; $this->email = $email; }}
class Page{ // The type `property<User>|string` accepts a key or any string. In the // editor, a string written here offers the property names of `User`. public static function field(User $user, property<User>|string $name): string { ?property<User> $key = $name as ?property<User>; if ($key == null) { return 'no property named ' . ($name as string); } return ($key as string) . ': ' . $user->$key; }}
User $user = new User('Ada', 'ada@example.com');
echo Page::field($user, 'email'), "\n";
// "passwordHash" is a private property, so the function does not show it.echo Page::field($user, 'passwordHash'), "\n";
// A key made with `as` is accepted too.property<User> $key = 'name' as property<User>;echo Page::field($user, $key), "\n";email: ada@example.comno property named passwordHashname: AdaUpdate the properties a list of changes names
<?nvs// Updates only the properties that a list of changes names, and skips every other name.
class Profile{ public string $name = 'Ada'; public string $email = 'ada@example.com'; public string $city = 'London'; private string $role = 'member';
public function role(): string { return $this->role; }}
Profile $profile = new Profile();
// The changes to make, with the property names as keys.array<string> $changes = ['city' => 'Paris', 'role' => 'admin', 'phone' => '555'];
foreach ($changes as string $field => string $value) { // `as ?property<Profile>` gives `null` for "role", because it is private. // It also gives `null` for "phone", because `Profile` has no such property. ?property<Profile> $key = $field as ?property<Profile>; if ($key == null) { echo 'skipped: ', $field, "\n"; continue; } // This writes the property that the key names. $profile->$key = $value; echo 'updated: ', $field, "\n";}
echo $profile->name, ', ', $profile->city, ', ', $profile->role(), "\n";updated: cityskipped: roleskipped: phoneAda, Paris, memberUpdate an object from a json body
<?nvs// Updates an object with the fields that a JSON request body sends, and skips every other field.
// Text from a request is tainted, which means it came from outside your program.// A key can write tainted text only when every public property is `tainted string`.class Profile{ public tainted string $name = 'Ada'; public tainted string $city = 'London'; private string $role = 'member';
public function role(): string { return $this->role; }}
Profile $profile = new Profile();
// The body is {"city": "Paris", "role": "admin"}.var $changes = Core\Request::json() as array<mixed>;
foreach ($changes as tainted string $field => mixed $value) { // "role" is a private property, so `as ?property<Profile>` gives `null`. ?property<Profile> $key = $field as ?property<Profile>; if ($key == null) { echo 'skipped: ', $field, "\n"; continue; } $profile->$key = $value as tainted string; echo 'updated: ', $field, "\n";}
echo $profile->name, ', ', $profile->city, ', ', $profile->role(), "\n";updated: cityskipped: roleAda, Paris, memberA write of the wrong type
<?nvs// Shows what a read through a key gives, and what happens when a write or a name is wrong.
class User{ public string $email = 'ada@example.com'; public int $age = 36; private string $password = 'secret';}
User $user = new User();string $field = 'age';property<User> $key = $field as property<User>;$user->$key = 37;echo $user->age, ' ', $key as string, "\n";
// The key can name `$email` or `$age`, so a read gives `string|int`.string|int $value = $user->$key;echo $value is int ? 'an int' : 'a string', "\n";
// "password" is private. `as ?property<User>` gives `null`, and `as property<User>` throws.string $hidden = 'password';?property<User> $none = $hidden as ?property<User>;echo $none == null ? 'null' : 'a key', "\n";try { property<User> $bad = $hidden as property<User>;} catch (RuntimeError $e) { echo $e->message, "\n";}
// The key names `$age`, which is an `int`. Writing a string throws an error.try { $user->$key = 'old';} catch (RuntimeError $e2) { echo $e2->message, "\n";}37 agean intnulla `string` of 8 bytes is not one of `User`'s public declared properties: `$age`, `$email``User` declares property `age` as `int`, so a string cannot be written to itA parent key on a child object
<?nvs// Shows a key of a parent class used on an object of a child class.
class Animal{ public string $name = 'Rex';}
class Dog extends Animal{ public string $breed = 'beagle';}
Dog $dog = new Dog();
// A `Dog` has every property of an `Animal`, so a `property<Animal>` key works on it.property<Animal> $key = 'name' as property<Animal>;echo $dog->$key, "\n";
// A `property<Animal>` key is also a `property<Dog>` key.property<Dog> $dogKey = $key;echo $dog->$dogKey, "\n";RexRexA class with a readonly property
<?nvs// Shows that a key cannot write to a class with a public `readonly` property.// The key could name `$id`, so the write does not compile.// proof: compile-error
class Order{ public readonly int $id; public string $status = 'new';
public function constructor(int $id) { $this->id = $id; }}
Order $order = new Order(7);property<Order> $key = 'status' as property<Order>;$order->$key = 'paid';error[E0782]: `Order::$id` is `readonly`, so only `Order`'s constructor writes it --> 07-a-class-with-a-readonly-property.nvs:19:1 |19 | $order->$key = 'paid'; | ^^^^^^^^^^^^ a `property<Order>` may name any of Order's public properties, and this write cannot know which one it holds = help: write the property out to name a different one, or drop the modifier if the property is meant to be assignable
error: aborting due to 1 errorTo read what a code means and how to fix it, run `nvs agent show <code>`.An attribute that names properties of its class
<?nvs// Shows an attribute (data written above a class) with a list of the class's property names.
// In the declaration, `static` is the class that uses the attribute. Here that class is `Post`.attribute Search on class { fields: array<property<static>> }
#[Search(fields: ['title', 'author'])]class Post{ public string $title = 'Hello'; public string $author = 'Ada'; public string $body = 'The first post.';}
Post $post = new Post();
// `Core\Attributes::get` reads the attribute of `Post`. `fields` has the type `array<property<Post>>`.var $search = Core\Attributes::get<Search>(Post::constructor);if ($search != null) { array<property<Post>> $fields = $search->fields; foreach ($fields as var $field) { echo $field as string, ': ', $post->$field, "\n"; }}title: Helloauthor: AdaDetails
In property<T>, T must be a class with at least one public property. An interface, an enum or a type such as int is the error E0799.
A name written directly in the code is checked while compiling. "emial" as property<User> is the error E0405. You can pass a string literal to a parameter of type property<User> or ?property<User> without as. The compiler converts it to a key, and a wrong name is E0405. In a variable, a return value or an array, a string literal stays a string.
as gives the same RuntimeError for an unknown name and for a private or protected property. The message lists the public properties of the class.
$obj->$key and $obj->{$expr} read or write the property that the key names. With a variable of type string there, the program does not compile (E0235).
A read through a key has the type of every property the key can name, as a union. For a class with a string property and an int property, the type is string|int.
A write through a key is checked when the program compiles and again when it runs. When it compiles, the value must have the type of at least one property. true written through a key of a class with only string properties is E0401. When it runs, the value must have the type of the property the key names. If it does not, the write throws a RuntimeError.
A tainted value is input from outside the program, such as a request. A secret value, such as a password, must not be printed. Such a value can only be written through a key when every property the key can name allows it. If one property is a plain string, writing a tainted string is E0401.
If the class has a public readonly property, a write through a key does not compile (E0782). A private readonly property is never named by a key, so a write through a key still compiles.
A property<Animal> key works on a Dog when Dog extends Animal. You can also store it in a variable of type property<Dog>. A property<Dog> key on an Animal is the error E0235.
An attribute declaration lists the fields of an attribute. In such a field, static is the class that uses the attribute. For #[Search(...)] above class Post, static is Post. For an attribute above a property, a method or a parameter, static is the class that contains it. A field typed property<static> or array<property<static>> takes the names of that class's public properties. The name of a private property, or of a property of another class, is E0405 at the string.
Core\Attributes::get<Search>(Post::constructor) reads the Search attribute of Post. It gives fields the type array<property<Post>>, so $post->$field reads each property that fields names.
$key as string gives the property name. Two keys are equal when they name the same property. A key written in the code and a key converted from a variable are equal when the name is the same.
Property paths
A property path is a value that names a property across related objects, such as customer.address.city.
The type propertyPath<Order> contains paths that start at the class Order. Each name in a path is a public property of the class that the name before it reaches. That property can be an object, a nullable object or an array. A string written in a call to a propertyPath<Order> parameter is checked when the program compiles. as checks any other string while the program runs, and throws an error if a name is wrong. as ?propertyPath<Order> gives null instead.
After an array property, @key is an element's key and @value is the element, as in authors.@value.name. A property named key or value keeps its name: authors.value.
Good to know: a private or protected property is never part of a path. A path can come back to the same class, such as parent.parent.name.
The examples below go from an order to its customer and lines, sort by a property the web address names, show the errors for a wrong path, and use @key and @value.
A path through a relation
<?nvs// Shows property paths that go from an order to its customer, its address and its lines.
class Address{ public string $city = 'Graz';}
class Customer{ public string $name = 'Ada'; public ?Address $address = null;}
class Line{ public string $sku = 'p-1'; public int $quantity = 1;}
class Order{ public Customer $customer; public array<Line> $lines = []; public int $total = 40;
public function constructor() { $this->customer = new Customer(); }}
class Report{ // The parameter type `propertyPath<Order>` accepts a path that starts at `Order`. // A string written in the call is checked when the program compiles. public static function sortBy(propertyPath<Order> $path): string { return 'sorted by ' . ($path as string); }}
// `customer` is a `Customer`, so `name` is a property of `Customer`.echo Report::sortBy('customer.name'), "\n";
// `address` is a `?Address`. A path can go through a nullable object.echo Report::sortBy('customer.address.city'), "\n";
// `lines` is an `array<Line>`. A path can go through an array of objects.echo Report::sortBy('lines.sku'), "\n";
// One name is a path too.echo Report::sortBy('total'), "\n";sorted by customer.namesorted by customer.address.citysorted by lines.skusorted by totalThe property to sort by from the address
<?nvs// Shows a list of orders sorted by a property that the web address names.
class Customer{ public string $name; private string $password = 'x9f2';
public function constructor(string $name) { $this->name = $name; }}
class Order{ public Customer $customer; public int $total;
public function constructor(string $name, int $total) { $this->customer = new Customer($name); $this->total = $total; }}
class Table{ public static function sortBy(?tainted string $field): string { // `as ?propertyPath<Order>` checks each name of the path while the program runs. // If one name is wrong, the result is `null`. ?propertyPath<Order> $path = $field as ?propertyPath<Order>; if ($path == null) { return 'not a property path, sorted by total'; } return 'sorted by ' . ($path as string); }}
// The address is `/orders?sort=customer.name&other=customer.password`.echo Table::sortBy(Core\Request::queryParameter('sort')), "\n";
// `password` is a private property, so it is not part of any path.echo Table::sortBy(Core\Request::queryParameter('other')), "\n";sorted by customer.namenot a property path, sorted by totalA path that starts at the calling class
<?nvs// Shows one method in a parent class that takes a path for each child class.
class Model{ // `propertyPath<static>` is a path that starts at the class the call names. // `Category::orderBy` takes paths of `Category`. public static function orderBy(propertyPath<static> $path): string { return 'ORDER BY ' . $path; }}
class Category extends Model{ public string $name = 'Books'; public ?Category $parent = null;}
class Product extends Model{ public Category $category; public int $price = 5;
public function constructor() { $this->category = new Category(); }}
echo Category::orderBy('parent.name'), "\n";
// A path can come back to the same class many times.echo Category::orderBy('parent.parent.parent.name'), "\n";
echo Product::orderBy('category.name'), "\n";ORDER BY parent.nameORDER BY parent.parent.parent.nameORDER BY category.nameA wrong path from a string
<?nvs// Shows the error `as` throws for a path that is not valid.
class Customer{ public string $name = 'Ada'; private string $password = 'x9f2';}
class Order{ public Customer $customer; public int $total = 40;
public function constructor() { $this->customer = new Customer(); }}
// The first path is valid. Each other path has one wrong part, and the message names it.array<string> $fields = ['customer.name', 'customer.age', 'customer.password', 'total.amount', 'customer.'];foreach ($fields as string $field) { try { propertyPath<Order> $path = $field as propertyPath<Order>; echo 'valid: ', $path as string, "\n"; } catch (RuntimeError $e) { echo $e->message, "\n"; }}valid: customer.namea `string` of 12 bytes is not a property path of `Order`: `Customer` has no public property `$age`a `string` of 17 bytes is not a property path of `Order`: `Customer` has no public property `$password`a `string` of 12 bytes is not a property path of `Order`: `Order`'s property `$total` is not an object, so the path cannot continue after ita `string` of 9 bytes is not a property path of `Order`: it has an empty partA wrong path written in the code
<?nvs// Shows that a path written in the code is checked while compiling.// `Customer` has no property `$nme`, so this program does not compile.// proof: compile-error
class Customer{ public string $name = 'Ada';}
class Order{ public Customer $customer;
public function constructor() { $this->customer = new Customer(); }}
class Report{ public static function sortBy(propertyPath<Order> $path): string { return 'sorted by ' . ($path as string); }}
echo Report::sortBy('customer.nme'), "\n";error[E0405]: `Customer` has no public property `$nme` --> 05-a-wrong-path-written-in-the-code.nvs:29:31 |29 | echo Report::sortBy('customer.nme'), "\n"; | ^^^ this part of the path is checked here = help: each part of a property path names a public property of the class the path has reached: `Customer` has `$name`
error: aborting due to 1 errorTo read what a code means and how to fix it, run `nvs agent show <code>`.A condition on an array key and element
<?nvs// Shows a condition whose paths go into an array with `@key` and `@value`.
class Author{ public string $name = 'Ada';}
class Book{ public array<string> $tags = []; public array<Author> $authors = [];
// Each hole of `$condition` is a path of the class the call names. public static function find(string<propertyPath<static>> $condition): void { echo $condition, "\n"; // Inside the method, `$condition` is a `string`. This line checks its holes against `Book`. var $checked = $condition as string<propertyPath<self>>; bool $hole = false; // `Core\Str::parts` gives the text and the holes in turn. The first part is text. foreach (Core\Str::parts($checked) as var $part) { if ($hole) { echo ' path ', $part as string, "\n"; // `Core\Reflect::steps` gives one row for each step of the path. foreach (Core\Reflect::steps($part as propertyPath<self>) as var $step) { echo ' ', $step->name(), ': ', $step->type() ?? 'no type', "\n"; } } $hole = !$hole; } }}
// `@key` is the key of an element. `@value` is the element.Book::find("{tags.@value} = 'new' AND {tags.@key} < 3");
// `@value` of `authors` is an `Author`, so the path can go on to `name`.Book::find("{authors.@value.name} = 'Ada'");
// `authors.name` is a shorter way to write `authors.@value.name`.Book::find("{authors.name} = 'Ada'");{tags.@value} = 'new' AND {tags.@key} < 3 path tags.@value tags: array<string> @value: string path tags.@key tags: array<string> @key: int|string{authors.@value.name} = 'Ada' path authors.@value.name authors: array<Author> @value: Author name: string{authors.name} = 'Ada' path authors.name authors: array<Author> name: stringDetails
Every name in a path but the last must be a property whose type is a class C, a ?C, an array<E> or a ?array<E>. After a class, the next name is a property of C. The last name can be any public property.
After an array, the next part is @key, @value or a property of the element class:
@keyis the key of an element. Its type isint|string, and the path ends there.@valueis the element, of typeE. The path can end there. IfEis a class, the path can go on to its properties. IfEis an array, the path can take@keyor@valueagain, such asgrid.@value.@key.- A property of the element class directly after the array is a shorter way to write
@valueand that property.authors.nameis the same path asauthors.@value.name.
A property name never starts with @. So authors.value is always the property $value, and authors.@value is always the element. Any other word after @, such as @index, is the error E0405. So is @key after a property that is not an array, and any part after @key.
Core\Reflect::steps returns one entry for each part of the path. The entry for @key is named @key, with the type int|string. The entry for @value is named @value, with the element's type, such as Author. Both entries are public. A shorter path such as authors.name has no @value entry.
A path written directly in the code is checked while compiling, one name at a time. This is true for "customer.nme" as propertyPath<Order> and for a string literal at a parameter typed propertyPath<Order>. A wrong name is the error E0405, and the error points at that name. A path that continues after a property that is not an object or an array, such as total.x, is also E0405.
as checks any other string while the program runs. If the path is wrong, it throws a RuntimeError. The message names the class and the part that is wrong. The empty string and a path that ends with . throw too, because they have an empty part.
A path is not used to read a value. $order->$path does not compile (E0235). Use a property<T> key to read or write one property.
$path as string gives the text. Two paths are equal when their text is equal. A path written in the code and a path converted from a variable are equal when the text is the same.
Strings with holes
A string with holes is a string that contains names between { and }, such as "{total} > 100 AND {customer.email} LIKE ?".
The type is written string<K>. It is one string, not a collection like array<K>. K says what a hole may contain: property<T>, propertyPath<T>, or a set of strings such as 'name'|'count'. A string written in a call to a string<K> parameter is checked when the program compiles. as checks any other string while the program runs, and throws an error if a hole is wrong.
Good to know: a parameter such as string<propertyPath<Order>>|Filter takes a string or a Filter object. A string written there is checked too. {{ is one { and }} is one }. Only the holes are checked. A tainted string (text from outside the program) stays tainted after as string<K>, so a condition from a request cannot be the text of a database query. Core\Str::parts splits the string into its text and holes.
The examples below check the property paths in a query condition, fill a message template, check a condition built while the program runs, and show a wrong hole that does not compile.
A condition with checked property paths
<?nvs// Shows a query condition whose property names are checked when the program compiles.
class Customer{ public string $name = 'Ada'; public string $email = 'ada@example.com';}
class Order{ public Customer $customer; public int $total = 40; public string $status = 'paid';
public function constructor() { $this->customer = new Customer(); }}
class Query{ // Each hole in `$condition` is a property path of `Order`. // A string written in the call needs no `as`. public static function where(string<propertyPath<Order>> $condition): string { return 'WHERE ' . ($condition as string); }
// Each hole in `$list` is a property name of `Customer`. public static function select(string<property<Customer>> $list): string { return 'SELECT ' . ($list as string); }}
echo Query::select('{name}, {email}'), "\n";echo Query::where('{total} > 100 AND {customer.email} LIKE ?'), "\n";
// The text between the holes is not checked. Only the holes are checked.echo Query::where("{status} IN ('paid', 'sent')"), "\n";SELECT {name}, {email}WHERE {total} > 100 AND {customer.email} LIKE ?WHERE {status} IN ('paid', 'sent')A message with named values
<?nvs// Shows a message template whose holes must be one of a few names.
class Message{ // A hole in `$template` is `{name}` or `{count}`. Any other hole does not compile. public static function fill(string<'name'|'count'> $template, string $name, int $count): string { string $text = ''; bool $hole = false; // `Core\Str::parts` gives the text and the holes in turn, starting with text. foreach (Core\Str::parts($template) as var $part) { if (!$hole) { $text = $text . ($part as string); } elseif ($part == 'name') { $text = $text . $name; } else { $text = $text . ($count as string); } $hole = !$hole; } return $text; }}
echo Message::fill('Hello {name}, you have {count} new messages.', 'Ada', 3), "\n";
// `{{` is one `{` and `}}` is one `}`. They are text, not holes.echo Message::fill('{{name}} is replaced by {name}.', 'Ada', 0), "\n";Hello Ada, you have 3 new messages.{name} is replaced by Ada.A condition built while the program runs
<?nvs// Shows how a string built while the program runs is checked with `as`.
class Order{ public int $total = 40; public string $status = 'paid';}
class Filter{ public static function check(string $text): string { // `as ?string<propertyPath<Order>>` checks each hole. If one is wrong, the result is `null`. ?string<propertyPath<Order>> $condition = $text as ?string<propertyPath<Order>>; if ($condition == null) { return 'not valid: ' . $text; } return 'valid: ' . ($condition as string); }}
string $field = 'status';echo Filter::check('{' . $field . "} = 'paid'"), "\n";
// `Order` has no property `price`.echo Filter::check('{price} > 10'), "\n";
// A `{` with no `}` after it is not valid.echo Filter::check('{total > 10'), "\n";
// `as string<propertyPath<Order>>` throws an error that names the wrong hole.try { var $bad = ('{total.amount}' . ' > 1') as string<propertyPath<Order>>;} catch (RuntimeError $e) { echo $e->message, "\n";}valid: {status} = 'paid'not valid: {price} > 10not valid: {total > 10a `string` of 18 bytes is not a string with holes of `Order`: in the hole `{total.amount}`, `Order`'s property `$total` is not an object, so the path cannot continue after itA wrong hole written in the code
<?nvs// Shows that the holes of a string written in the code are checked while compiling.// `Order` has no property `$totl`, so this program does not compile.// proof: compile-error
class Order{ public int $total = 40;}
class Query{ public static function where(string<property<Order>> $condition): string { return 'WHERE ' . ($condition as string); }}
echo Query::where('{totl} > 10'), "\n";error[E0405]: `Order` has no public property `$totl` --> 04-a-wrong-hole-written-in-the-code.nvs:19:21 |19 | echo Query::where('{totl} > 10'), "\n"; | ^^^^ this hole is checked here = help: each hole names a public property of `Order`, which has `$total`
error: aborting due to 1 errorTo read what a code means and how to fix it, run `nvs agent show <code>`.Details
K is property<T>, propertyPath<T> or a set of strings, such as 'asc'|'desc'. Any other K, such as string<int>, does not compile (E0860).
A hole is everything between { and }, spaces included. { total } is not the hole {total}. An empty hole {}, a { with no } and a } with no { do not compile (E0861).
A string written directly in the code is checked while compiling, one hole at a time. This is true for a string literal at a parameter typed string<K>, and for "{total}" as string<property<Order>>. A hole that is not a property of the class is the error E0405. A hole that is not in a set of strings is the error E0861. The error points at the wrong hole.
Only a parameter takes a string literal with no as. A local variable typed string<K> needs as for a literal too, or the program does not compile (E0401).
A parameter can be a union of string<K> and other types, such as string<propertyPath<Order>>|Filter. A string literal there is checked as a string<K>. This works when string<K> is the only type in the union that takes a string. If the union also has string, mixed or a second string<K>, the literal is a plain string.
as checks any other string while the program runs. If a hole is wrong, it throws a RuntimeError, and the message names the hole and what is wrong with it. as ?string<K> gives null instead.
as string<K> keeps tainted. A tainted string converts to a tainted string<K>. A parameter typed string<K> does not take it (E0401).
$text as string gives the text as written, so {{ stays {{. Two values are equal when their text is equal. A string written in the code and a string converted from a variable are equal when the text is the same.
Use this when a name comes from outside
Section titled “Use this when a name comes from outside”Use property<T> for one property of one class. Use propertyPath<T> when the name goes through
objects that are properties of other objects, such as customer.address.city. After an array
property, @key names the key of an element and @value names the element. An example is
authors.@value.name. Use string<K> for a longer text that contains names, such as a filter for a
database query.
An attribute is data written above a class, such as #[Search(fields: ['title'])]. When you declare
an attribute, the type property<static> takes the name of a property of the class below it. The
compiler checks each name.
Do and don’t
Section titled “Do and don’t”- Do convert a name from a request with
as ?property<T>, and handlenull. - Do write a fixed name in the code, so the compiler checks it.
- Don’t make a property public only so that a key can name it.
