我在PHP类中如何定义多个常量之间存在任何显着差异:
这个:
<?php
abstract class Some_Class
{
const CONSTANT_ONE = 101;
const CONSTANT_TWO = 102;
const CONSTANT_THREE = 103;
}
可能更接近于定义的JS风格:
<?php
abstract class Some_Class
{
const CONSTANT_ONE = 101,
CONSTANT_TWO = 102,
CONSTANT_THREE = 103
;
}
答案 0 :(得分:3)
关于语法没有区别。
即使是PHP-FIG Standards concerning constants也允许使用第二种形式的文档(他们称之为复合语句)。
我个人更喜欢第一种形式:)
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";
}