I think the problem here is you haven't really laid out all the possible scenarios. Let's try doing this in English and we'll see where we get:
- If $major_length is 4800, return 18
- Otherwise, If $major_length is 8552:
- If $val is 4, return 33
- If $val is 1, return 18
- Otherwise, ?????
- Otherwise, ?????
You haven't addressed the possibility that (major_length is neither 4800 nor 8852) nor that (major_length is 8852 but val is neither 1 nor 4). Now, it may be that in your application these scenarios are impossible, but the ?: operator does not allow you to simple ignore them. You may find it easier to use an if-else construct instead:
if ($major_length == 4800) {
$result = 18;
} elsif ($major_length == 8552) {
if ($val == 4) {
$result = 33;
} elsif ($val == 1) {
$result = 18;
}
}
You still have the possibility of those unhandled situations, but now they'll simply result in $result not getting assigned at all.