I am trying to partially mimick Enum behaviour in PHP, and I'd like to take advantage of PHP's mixed type aswell.
Consider this example of my code (Using PHP PDO underlying):
class DBH {
/** The current database handler **/
private $dbh;
const SQL_NOW = 1;
public function insert($table, $keyvaluepairs) {
$sql = "INSERT INTO `{$table}` (";
$values_sql = ") VALUES(";
$values = array();
foreach ($keyvaluepairs as $key => $value) {
if ($value == SELF::SQL_NOW) {
$sql .= "NOW(), ";
}
else {
$sql .= "`${key}`, ";
$values_sql .= "?, ";
$values[] = $value;
}
}
$query = substr($sql, 0, -2).substr($values_sql, 0, -2).")";
return $this->query($query, $values);
}
}
All $value values are possible, as long as they are allowed by SQL natively, but PDO does not restrict itself to SQL, it can communicate with any RMDMS.
Currently my SQL_NOW clashes with the (int)1 value as far as I know.
How can I ensure that no value-clashing occurs, if possible, can I have an const/enum without value?