Your issue is not OOP-related.
You're passing the value of 1 into your $lv
variable. That makes for the following situation:
$lv = 1;
if ( $lv != 1 || $lv != 2 ){
throw new Exception('Wrong access level!');
}
We can separate what's in the if statement:
- The first expression (
$lv != 1
) will be evaluated to false because 1 does equal 1.
- The second expression (
$lv != 2
) will be evaluated to true because 1 does not equal 2.
In this case:
false || true
Evaluates to true.
What you want instead is to change the or operator to an and operator:
if ( $lv != 1 && $lv != 2 ){
throw new Exception('Wrong access level!');
}
Or, equivalently:
if ( !( $lv == 1 || $lv == 2 )){
throw new Exception('Wrong access level!');
}