PHP 8.6 vyšlo. DressCode na něj váš kód přepíše. Přechod na novější PHP →

Jména

PHP je jedno, jestli se metoda jmenuje getTotal(), nebo get_total(), čtenářům kódu ne. Sekce naming určuje, jak se píšou jména, která vymýšlíte vy, od tříd po proměnné, a jestli jméno rozhraní, traitu, výjimky nebo abstraktní třídy nese slovo svého druhu.

Každý druh jména má vlastní klíč a hodnotou je zápis: PascalCase, camelCase, UPPER_CASE nebo snake_case. PSR-1 předepisuje zápis jen u tříd, metod a konstant tříd, a tak standardy psr12 a perCs nastavují jen ty; Nette Coding Standard nastavuje všechny a konstanty píše v PascalCase.

naming:
	class: PascalCase
	method: camelCase
	constant: UPPER_CASE
	variable: camelCase

Porušení se jen hlásí, nikdy neopraví: jméno metody nebo vlastnosti by se muselo změnit i všude, kde se používá, a to z jednoho souboru vidět není. Jméno, které má zůstat, jak je, třeba metoda stream wrapperu, kterou PHP volá jménem stream_open, se vyjme vzorem v naming.except.

class Order
{
	public function get_total(): int  // The method `get_total` must be written in camelCase.
	{
		return 0;
	}
}

naming.class

The case of the name of a class, an interface, a trait and an enum, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs PascalCase, psr12 PascalCase, nette PascalCase, symfony PascalCase, laravel keep · pokrývá Squiz.Classes.ValidClassName

naming.constant

The case of the name of a class constant and a const outside a class, a constant of an enum passing in this case or in that of enumCase, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs UPPER_CASE, psr12 UPPER_CASE, nette PascalCase, symfony UPPER_CASE, laravel keep · pokrývá Generic.NamingConventions.UpperCaseConstantName, Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase

naming.enumCase

The case of the name of a case of an enum, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs PascalCase, psr12 keep, nette PascalCase, symfony PascalCase, laravel keep

naming.property

The case of the name of a property, a promoted constructor parameter included, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette camelCase, symfony keep, laravel keep · pokrývá Squiz.NamingConventions.ValidVariableName, Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps

naming.method

The case of the name of a method, those beginning with __ being PHP's, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs camelCase, psr12 camelCase, nette camelCase, symfony camelCase, laravel keep · pokrývá Generic.NamingConventions.CamelCapsFunctionName, PSR1.Methods.CamelCapsMethodName, PSR1.Methods.CamelCapsMethodName.NotCamelCaps, Squiz.NamingConventions.ValidFunctionName

naming.function

The case of the name of a function, those beginning with __ being PHP's, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette camelCase, symfony keep, laravel keep · pokrývá Generic.NamingConventions.CamelCapsFunctionName, Squiz.NamingConventions.ValidFunctionName

naming.variable

The case of the name of a variable and a parameter, $this, the superglobals and a placeholder such as $_ excepted, which is reported and never renamed.

  • PascalCase: a capital first and a lowercase letter somewhere, FooBar, a name of two letters such as IO passing
  • camelCase: a lowercase letter first, fooBar
  • UPPER_CASE: capitals, digits and underscores, FOO_BAR
  • snake_case: lowercase letters, digits and underscores, foo_bar
  • Pascal_Snake_Case: words joined by underscores, each beginning with a capital, WP_REST_Request, a PascalCase name passing too
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette camelCase, symfony keep, laravel keep · pokrývá Squiz.NamingConventions.ValidVariableName, Squiz.NamingConventions.ValidVariableName.NotCamelCaps, Squiz.NamingConventions.ValidVariableName.StringNotCamelCaps

naming.except

The patterns of names never reported, whatever their kind, as the methods of a stream wrapper or a replacement for a native function.

  • seznam regulárních výrazů

Výchozí [] · standardy: perCs [], psr12 [], nette [], symfony [], laravel []

naming:
	method: camelCase
	except:
		- '~^stream_~'
class MemoryStream
{
	public function stream_open(string $path, string $mode): bool
	{
		return true;
	}
}

naming.abstractClassAffix

The word Abstract in front of the name of an abstract class, AbstractFoo, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · pokrývá SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming

naming.interfaceAffix

The word Interface at the end of the name of an interface, FooInterface, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · pokrývá SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming

naming.traitAffix

The word Trait at the end of the name of a trait, FooTrait, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · pokrývá SlevomatCodingStandard.Classes.SuperfluousTraitNaming

naming.exceptionAffix

The word Exception at the end of the name of an exception, FooException, which is reported and never renamed.

  • forbidden: never there
  • required: always there
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette keep, symfony keep, laravel keep · pokrývá SlevomatCodingStandard.Classes.SuperfluousExceptionNaming

naming.errorAffix

The word Error at the end of the name of a class that is not abstract, FooError, which is reported and never renamed.

  • forbidden: never there
  • keep: nic se nevynucuje, kód zůstane, jak je

Výchozí keep · standardy: perCs keep, psr12 keep, nette forbidden, symfony keep, laravel keep · pokrývá SlevomatCodingStandard.Classes.SuperfluousErrorNaming

Zobrazit na GitHubu · Nahlásit problém se stránkou na GitHubu · 7. 11. 2026