Skip to content

Person names

phil/contact

A ContactCard keeps a person's name as one text, name, and may also keep it in its parts, structuredName, a PersonName. The parts let the name be written and sorted as its culture does: Charles de Gaulle sorts under Gaulle in French, Herman Van Rompuy under Van Rompuy in the Dutch of Belgium, and Bartók Béla is written family name first in Hungarian.

$name = PersonName::of(given: 'Charles', family: 'Gaulle', particle: 'de', culture: 'fr');

$name->display();   // "Charles de Gaulle"
$name->sortKey();   // "Gaulle, Charles de"

$card = ContactCard::of(structuredName: $name);
$card->name;        // "Charles de Gaulle"

The parts

PartExampleNote
givenAdaThe given name
additional['Augusta']Middle names, at most PersonName::MAX_ADDITIONAL (10)
particlede, van der, d'Goes with a family name; an elided particle, ending with ' or ’, is written against it
familyGaulleThe family name, without its particle
secondFamilyMárquezA second family name, as in Spanish
honorificDr.Written by formal()
generationJr., IIIWritten after the name
credentialPhDWritten by formal(), after a comma
culturefr-CAA BCP 47 language tag; _ is read as -
orderNameOrder::FamilyFirstWins over the order of the culture; none by default

PersonName::of() trims each text; an empty one is none. A name has a given name or a family name, each part is 255 characters or fewer and holds no control character, and a language tag has a language of two or three letters and parts of one to eight letters or digits after it, 35 characters in all. InvalidContact is thrown otherwise. On a card, the display form of the name is the card's name when the card is given none, and it is 255 characters or fewer too.

Writing and sorting

MethodGivesCharles de Gaulle in French
display()The name as written every day, generation includedCharles de Gaulle
formal()With the honorific and the credentialGén. Charles de Gaulle, PhD
familyName()The family name as written, particle and second family name includedde Gaulle
surname()The family name with its particle, without the second family namede Gaulle
sortFamily()The family name a list sorts byGaulle
sortKey()The text a list sorts byGaulle, Charles de
separator()What separates the partsa space
displayOrder()The order the name is written inNameOrder::GivenFirst
equals()Whether two names have the same parts

Given name first, display() writes the given name, the additional names and the family name; family name first, the family name, the additional names and the given name, as Vietnamese writes Võ Nguyên Giáp. Chinese, Japanese and Korean names written in their own characters are joined without a space, 毛泽东, and with one when romanised, Mao Zedong.

sortKey() puts the sorted family name first, then the given and additional names, then what the sort leaves out of the particle: Gogh, Vincent van. What the key keeps of a particle starts with a capital, as a sorted list prints it: Du Bellay, Joachim. A culture that sorts by the given name puts it first: Giáp, Võ Nguyên. Sort the keys with a collator of the reader's language, Collator::compare() of ext-intl: the key orders the parts, the collator orders the letters.

Each method takes a NameConvention as an optional argument, which wins over the name's culture.

The conventions of the library

NameConventions::for($culture) gives the convention of a culture, by its language and, for Dutch, its country:

CultureOrderSort keyExample
Chinese, Japanese, KoreanFamily name first, own characters joinedFamily name毛泽东 → 毛, 泽东
HungarianFamily name firstFamily nameBartók Béla → Bartók, Béla
VietnameseFamily name firstGiven nameVõ Nguyên Giáp → Giáp, Võ Nguyên
IcelandicGiven name firstGiven nameBjörk Guðmundsdóttir → Björk, Guðmundsdóttir
Dutch of the NetherlandsGiven name firstWithout the particleVincent van Gogh → Gogh, Vincent van
German, PortugueseGiven name firstWithout the particleUrsula von der Leyen → Leyen, Ursula von der
FrenchGiven name firstWithout a leading de or d'Jean de La Fontaine → La Fontaine, Jean de
SpanishGiven name firstWithout a leading deBartolomé de las Casas → Las Casas, Bartolomé de
Any other, Dutch of Belgium includedGiven name firstWith the particleHerman Van Rompuy → Van Rompuy, Herman

A name without a culture follows the last row. An application that knows a culture better builds its own NameConvention — its order, the leading words of a particle dropped from the sort key, whether the whole particle is dropped, whether names sort by the given name, whether names in Chinese, Japanese or Korean characters are joined — and gives it to the methods.

In the other formats

FormatThe structured name
vCardN, with the second family name and the generation of RFC 9554 when the name has them, LANGUAGE from the culture and SORT-AS when the culture sorts the name otherwise than it is written
schema.orggivenName, additionalName, familyName, honorificPrefix and honorificSuffix (generation and credential) of the Person
JSContactThe components of name, its sortAs, and the card's language — see JSContact
StorageThe structuredName key — see Storage