note 84182 deleted from language.oop5.constants by cmb
| From: | cmb@php.net | Date: | Wed, 31 Aug 2016 17:24:02 +0000 |
| Subject: | note 84182 deleted from language.oop5.constants by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206444@lists.php.net to get a copy of this message | ||
Note Submitter: elmar huebschmann
----
The major problem of constants is for me, you cant use them for binary flags.
<?php
class constant {
const MODE_FLAG_1 = 1;
const MODE_FLAG_2 = 2;
const MODE_FLAG_3 = 4;
const DEFAULT_MODE = self::FLAG_1 | self::FLAG_2
private function foo ($mode=self::DEFAULT_MODE) {
// some operations
}
}
?>
This code will not work because constants can't be an calculation result. You could use
<?php
const DEFAULT_MODE = 3;
?>
instead, but we use flags to be value indipendent. So you would miss target with it. Only way is to
use defines like ever before.