1

For example:

class Boolean extends AbstractFilter
{
    const TYPE_BOOLEAN        = 1;
    const TYPE_INTEGER        = 2;
    const TYPE_FLOAT          = 4;
    const TYPE_STRING         = 8;
    const TYPE_ZERO_STRING    = 16;
    const TYPE_EMPTY_ARRAY    = 32;
    const TYPE_NULL           = 64;
    const TYPE_PHP            = 127;
    const TYPE_FALSE_STRING   = 128;
    const TYPE_LOCALIZED      = 256;
    const TYPE_ALL            = 511;

Why do not define like 1 2 3 4 5 and define 1 2 4 8 16?

3 Answers3

1

Because you can use Bitwise operations on these numbers. Each of them (binary speaking) represents a single one and the rest as zeroes. So you can manipulate a range of options on a single byte. Say, if you add 1000 + 0100 you will get 1100 and the information is kept.

The same logic is applied on the second paramenter of json_encode, say json_encode($array, JSON_HEX_TAG | JSON_HEX_APOS).

Jean Carlo Machado
  • 1,480
  • 1
  • 15
  • 25
0

Because you can then OR them in your filter:

TYPE_INTEGER or TYPE_FLOAT finds either integers or floats

The TYPE_ALL gives it away: that is all the other values ORed together.

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
0

you can find more details of you answer here

suggestion about your question is That why computer science use 1 2 4 8 16 and so on..not the zend framework only.

vrkansagara
  • 606
  • 6
  • 13