我是否需要在括号中包含PHP内置函数?

Do I need to enclose PHP built-in functions in parentheses?

Are these the most proper ways?

(empty($UrlArray[1])), (is_numeric($UrlArray[1])), (strlen($UrlArray[1]) == 4)

Or, are these the most proper ways?

empty($UrlArray[1]), is_numeric($UrlArray[1]), strlen($UrlArray[1]) == 4

This one works but I'm wondering if I have too many parentheses.

( ( (empty($UrlArray[1])) OR ( (!empty($UrlArray[1])) AND (is_numeric($UrlArray[1])) AND (strlen($UrlArray[1]) == 4) ) ) AND (count($UrlArray) < 3) )

If I omit the parentheses that enclose the PHP built-in functions the code snippet still works.

( ( empty($UrlArray[1]) OR ( !empty($UrlArray[1]) AND is_numeric($UrlArray[1]) AND strlen($UrlArray[1]) == 4 ) ) AND count($UrlArray) < 3 )

I have always enclosed the PHP built-in functions in parentheses. But I am just wondering if that is the best way.

Thanks.

No. You don't need to wrap functions in parentheses. In fact, if I had to maintain code like that, it would probably drive me crazy.

Seems like it would only add to confusion, especially when you already have a lot of parentheses. It will make them more difficult to match up.

In your first example however, you have this:

(strlen($UrlArray[1]) == 4)

IMO, this one is fine. I would probably wrap the entire comparison in parentheses like this, but I would NOT do something like this:

((strlen($UrlArray[1])) == 4)

I might also format it for readability:

if (
    count($UrlArray) < 3
    && (
        empty($UrlArray[1])
        || (
            !empty($UrlArray[1])
            && is_numeric($UrlArray[1])
            && strlen($UrlArray[1]) == 4
        )
    )
) {
    // do something
}