4

Is there any significant difference in how I define multiple constants in PHP class between:

this:

<?php
abstract class Some_Class
{
    const CONSTANT_ONE   = 101;
    const CONSTANT_TWO   = 102;
    const CONSTANT_THREE = 103;
}

and probably closer to JS style of defining:

<?php
abstract class Some_Class
{
    const CONSTANT_ONE   = 101,
          CONSTANT_TWO   = 102,
          CONSTANT_THREE = 103
    ;
}
DeadMoroz
  • 270
  • 1
  • 3
  • 13

1 Answers1

6

Regarding syntax there is no difference.

Even the PHP-FIG Standards concerning constants allows the use of the second form documentation-wise (they call it compound statements).

Personally I prefer the first form :)

abstract class Some_Class {
    /**
     * @var int CONSTANT_ONE This constant is magical
     */
    const CONSTANT_ONE   = 101;

    /**
     * @var float CONSTANT_TWO This is Pi!
     */
    const CONSTANT_TWO   = 3.14;

    /**
     * @var string CONSTANT_THREE The magical door number
     */
    const CONSTANT_THREE = "103a";
}
Ricardo Velhote
  • 4,630
  • 1
  • 24
  • 30