Class constants can be read by importing the class or fully addressing it by namespace, so there is no reason to ever define a global constant.
There is no technical requirement for any class member to be defined in any particular case. The benefits of using different naming conventions is that it increases readability for programmers browsing the code, providing as much semantics as possible with little to no extra effort.
Using the uppercase underscored convention allows programmers to infer what is a fixed value.
There are many standard libraries that are in use within the PHP.Gt ecosystem that use camelCase property names. Most importantly, property naming convention must follow how libraries such as Dom or Fetch are defined, which provide standardised APIs that come from predefined web APIs.
It is easy to say static members are evil, but without concrete justification. The rule of thumb promoted in this guide it to never mix static with non-static members within the same class, as it leads to confusion and unreadability.
Good example (note that factory methods are within their own class, within their own file):
class FoodOrder {
public function __construct(Food $main, Food $side, Drink $drink) {
// ...
}
public function cook() {
// Do the cooking!
}
}
class FoodOrderFactory {
public static function createFromMenu(MenuItem $menu):FoodOrder {
$main = static::getMainCourseFromMenu($menu);
$side = static::getSideDishFromMenu($menu);
$drink = static::getDrinkChoiceFromMenu($menu);
return new FoodOrder($main, $side, $drink);
}
public static function createFromCsv(string $csv):FoodOrder {
list($main, $side, $drink) = static::parseCsv($csv);
return new FoodOrder($main, $side, $drink);
}
protected static function getMainCourseFromMenu(MenuItem $menu):Food {
// ...
}
protected static function getSideDishFromMenu(MenuItem $menu):Food {
// ...
}
protected static function getDrinkChoiceFromMenu(MenuItem $menu):Food {
// ...
}
protected static function parseCsv(string $csv):array {
// ...
}
}
Bad example:
class FoodOrder {
public function __construct(Food $main, Food $side, Drink $drink) {
// ...
}
public static function createFromMenu(MenuItem $menu):FoodOrder {
$main = static::getMainCourseFromMenu($menu);
$side = static::getSideDishFromMenu($menu);
$drink = static::getDrinkChoiceFromMenu($menu);
return new FoodOrder($main, $side, $drink);
}
public static function createFromCsv(string $csv):FoodOrder {
list($main, $side, $drink) = static::parseCsv($csv);
return new FoodOrder($main, $side, $drink);
}
protected static function getMainCourseFromMenu(MenuItem $menu):Food {
// ...
}
protected static function getSideDishFromMenu(MenuItem $menu):Food {
// ...
}
protected static function getDrinkChoiceFromMenu(MenuItem $menu):Food {
// ...
}
protected static function parseCsv(string $csv):array {
// ...
}
public function cook() {
// Do the cooking!
}
}