Is it possible to use PHP class constants as values in the config.xml file?

For example, if we have this config.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">

I would like to use a PHP class constant to output the value for the "mode". Is there a way to achieve this?


This should be possible using PHPs constant method.

Something like this:

$configValue = $this->scopeConfig->getValue(

$constantValue = constant($configValue);
  • I think the OP is asking how to use an existing class constant as the value in the XML. Ie something like <mode>Vendor\MyModule\Model\MyModel::MODE_VALUE</mode>, which for the record, doesn't work. – Dom Oct 31 '20 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.