Is it possible to define a class constant inside a class constructor function?
(based on certain conditions)
This contradicts the idea of class constants - they should not depend on a specific instance. Instead, you should use a variable.
However, if you insist on it, are very adventurous and can install PHP extensions, you can take a look at the runkit extension, which allows you to change classes and their constants at runtime. See this document: http://www.php.net/manual/en/function.runkit-constant-add.php
I do not think you can.
This also makes no sense - the class constant can be used in a static context, where there is no constructor in the first place.
Instead, you have to use a variable - what they are for.
Try looking here:
http://php.net/manual/en/language.oop5.constants.php
http://php.net/manual/en/language.oop5.static.php
Hope this helps.
Source: https://habr.com/ru/post/895570/More articles:Using SIGINT - c ++How to run cron-like scripts on Django? - pythonUsing dependency injection as an alternative to singleton - javaA portable way to catch signals and report a problem to the user - c ++How to set this soap php header? - soapGet all TCP connections opened by an application using C # - c #How to summarize group data with a weighted average? - rHow to get the number of open TCP connections held by a particular process in .NET. - .netPIVOT with MONTH () - sqlLine order in Java manifest files - javaAll Articles