0

the following part of my code worked fine under PHP7.0:

if (Config::LOG_LEVEL == 'debug' | 'basic' | 'light') {}

I have now updated to PHP7.2 and the following error message appears:

A non-numeric value encountered

does anyone have any idea how i can fix this bug?

arueckauer
  • 349
  • 5
  • 19
st0bsel
  • 15
  • 3
  • 4
    Possible duplicate of [Warning: A non-numeric value encountered](https://stackoverflow.com/questions/42044127/warning-a-non-numeric-value-encountered) – MyLibary Mar 01 '19 at 09:41
  • I just try to compare not to multiply – st0bsel Mar 01 '19 at 09:45
  • 1
    `Config::LOG_LEVEL` is probably an integer, and you are comparing it to a string. By the way, you are using bitwise operator on strings. – Zak Mar 01 '19 at 09:53
  • 1
    You CAN'T compare one value with a multiple of other values like that. You can only compare one value with **one** other value. If you need to check multiple values, you need to make multiple comparisons and connect them with an `OR` logical expression (`OR` or `||` in PHP). – Charlotte Dunois Mar 01 '19 at 10:21
  • 1
    _“the following part of my code worked fine under PHP7.0”_ - no, it didn’t: https://3v4l.org/urFQe - doesn’t even return true, when `Config::LOG_LEVEL` is (effectively) `basic` or `light`. _Only_ for `debug` this did what you thought it would to begin with. – 04FS Mar 01 '19 at 11:54

1 Answers1

1

As commented by others already, the code won't work as expected (usage of bitwise operator). Try in_array() instead.

in_array(Config::LOG_LEVEL, ['debug', 'basic', 'light'])

See https://3v4l.org/ScWH5

arueckauer
  • 349
  • 5
  • 19