I've got nearly 100 public static variables in a class that goes like this:
namespace Stats;
class City {
public static $name = '';
public static $mayor = '';
public static $population = '';
public static $gdp = '';
/* more like these */
}
Is there any way to group all these variables into one 'public static' statement so it looks like this?
namespace Stats;
class City {
public static {
$name = '';
$mayor = '';
$population = '';
$gdp = '';
}
}
class City {
public static $name = '',
$mayor = '',
$population = '',
...;
}
This does sound like a terrible idea though. The properties by their name sure sound like they're instance properties and have no business being static. Be aware that public static properties are essentially nothing more than global variables. Empty strings as default values also aren't a very usual thing to do; use null
instead.