I am returning to PHP after a period of absence. I am having problems with using class constants within another class's constructor:
The class HttpKeys contains all the keys the site uses for the $_POST array.
final class HttpKeys {
const EMPLOYEE_HTTP = 'employeeHttpKey';
const EMPLOYEE_LOG_OUT = 'employeeLogOutKey';
const EMPLOYEES_UPDATED = "employeesUpdated";
const LOCKS_UPDATED = "locksUpdated";
const MENU_ITEM_COUNTS_UPDATED = "menuItemCountsUpdated";
const MENU_ITEMS_UPDATED = "menuItemsUpdated";
const MODIFIERS_UPDATED = "modifiersUpdated";
const ORDERS_UPDATED = "ordersUpdated";
const PAYLOAD = "payload";
const PRODUCT_CATEGORIES_UPDATED = "productCategoriesUpdated";
const STATUS = "status";
const TERMINAL_HTTP = 'terminalHttpKey';
const TERMINAL_LOG_OUT = 'terminalLogOutKey';
const TERMINAL_REGISTRATION = 'terminalRegistrationKey';
const TIMESTAMP = "now";
}
However, These class constants are not always available in the following code. Is this by design or a bug?
require('HttpKeys.php');
class ClientUpdates {
function __construct() {
//-- this does not work
$i = HttpKeys::PRODUCT_CATEGORIES_UPDATED;
$this->getProductCategories();
}
private function getProductCategories() {
//-- this does not work
$j = HttpKeys::PRODUCT_CATEGORIES_UPDATED;
}
}
//-- this works
$k = HttpKeys::PRODUCT_CATEGORIES_UPDATED;
$clientUpdates = new ClientUpdates();
$clientUpdates = null;
unset($clientUpdates);
Thanks everyone for all the help - apologies for being a newbie once again.