Skip to main content
fixed a typo in the previous edit
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

For general constants, Coding standards / Naming Conventions says that constants should always be all-uppercase, with underscores to separate words and that module-defined constant names should also be prefixed by the module module machine name, all-uppercase, and an underscore charatercharacter.

Object-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores; instead, they opt for various forms of camel case.

Unfortunately, Object-oriented code doesn't mention class constants at all.

Which of the following is correct?

class Foo {
  const FOO_CONSTANT_VALUE = 'bar';
}
class Foo {
  const CONSTANT_VALUE = 'bar';
}
class Foo {
  const constantValue = 'bar';
}
  • const FOO_CONSTANT_VALUE = 'bar';
  • const CONSTANT_VALUE = 'bar';
  • const constantValue = 'bar';

For general constants, Coding standards / Naming Conventions says that constants should always be all-uppercase, with underscores to separate words and that module-defined constant names should also be prefixed by the module module machine name, all-uppercase, and an underscore charater.

Object-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores; instead, they opt for various forms of camel case.

Unfortunately, Object-oriented code doesn't mention class constants at all.

Which of the following is correct?

class Foo {
  const FOO_CONSTANT_VALUE = 'bar';
}
class Foo {
  const CONSTANT_VALUE = 'bar';
}
class Foo {
  const constantValue = 'bar';
}

For general constants, Coding standards / Naming Conventions says that constants should always be all-uppercase, with underscores to separate words and that module-defined constant names should also be prefixed by the module module machine name, all-uppercase, and an underscore character.

Object-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores; instead, they opt for various forms of camel case.

Unfortunately, Object-oriented code doesn't mention class constants at all.

Which of the following is correct?

  • const FOO_CONSTANT_VALUE = 'bar';
  • const CONSTANT_VALUE = 'bar';
  • const constantValue = 'bar';
fixed documentation links; Post Made Community Wiki
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

I'm trying to figure out the proper naming convention for class constants.

For general constants, the coding standards states:Coding standards / Naming Conventions says that constants should always be all-uppercase, with underscores to separate words and that module-defined constant names should also be prefixed by the module module machine name, all-uppercase, and an underscore charater.

Constants should always be all-uppercase, with underscores to separate words. This includes pre-defined PHP constants like TRUE, FALSE, and NULL. Module-defined constant names should also be prefixed by an uppercase spelling of the module they are defined by.

However, objectObject-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores,underscores; instead opting, they opt for various forms of camel case. And unfortunately

Unfortunately, the objectObject-oriented coding standardscode doesn't mention class constants at all.

So whichWhich of the following is correct?

class Foo {
  const FOO_CONSTANT_VALUE = 'bar';
}

or

class Foo {
  const CONSTANT_VALUE = 'bar';
}
class Foo {
  const FOO_CONSTANT_VALUE = 'bar';
}

or

class Foo {
  const CONSTANT_VALUE = 'bar';
}
class Foo {
  const constantValue = 'bar';
}
class Foo {
  const constantValue = 'bar';
}

I'm trying to figure out the proper naming convention for class constants.

For general constants, the coding standards states:

Constants should always be all-uppercase, with underscores to separate words. This includes pre-defined PHP constants like TRUE, FALSE, and NULL. Module-defined constant names should also be prefixed by an uppercase spelling of the module they are defined by.

However, object-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores, instead opting for various forms of camel case. And unfortunately, the object-oriented coding standards doesn't mention class constants at all.

So which of the following is correct?

class Foo {
  const FOO_CONSTANT_VALUE = 'bar';
}

or

class Foo {
  const CONSTANT_VALUE = 'bar';
}

or

class Foo {
  const constantValue = 'bar';
}

For general constants, Coding standards / Naming Conventions says that constants should always be all-uppercase, with underscores to separate words and that module-defined constant names should also be prefixed by the module module machine name, all-uppercase, and an underscore charater.

Object-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores; instead, they opt for various forms of camel case.

Unfortunately, Object-oriented code doesn't mention class constants at all.

Which of the following is correct?

class Foo {
  const FOO_CONSTANT_VALUE = 'bar';
}
class Foo {
  const CONSTANT_VALUE = 'bar';
}
class Foo {
  const constantValue = 'bar';
}
Tweeted twitter.com/#!/StackDrupal/status/140435512480632833
Source Link
user7
user7

What's the coding standard for class constants?

I'm trying to figure out the proper naming convention for class constants.

For general constants, the coding standards states:

Constants should always be all-uppercase, with underscores to separate words. This includes pre-defined PHP constants like TRUE, FALSE, and NULL. Module-defined constant names should also be prefixed by an uppercase spelling of the module they are defined by.

However, object-oriented names don't follow the normal conventions of prefixing the name with the module or using underscores, instead opting for various forms of camel case. And unfortunately, the object-oriented coding standards doesn't mention class constants at all.

So which of the following is correct?

class Foo {
  const FOO_CONSTANT_VALUE = 'bar';
}

or

class Foo {
  const CONSTANT_VALUE = 'bar';
}

or

class Foo {
  const constantValue = 'bar';
}