| Conditions | 7 |
| Paths | 5 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | public static function isSameTree2(?TreeNode $p, ?TreeNode $q): bool |
||
| 23 | { |
||
| 24 | $stack = [[$p, $q]]; |
||
| 25 | while ($stack) { |
||
|
|
|||
| 26 | [$m, $n] = array_pop($stack); |
||
| 27 | if (!$m && !$n) { |
||
| 28 | continue; |
||
| 29 | } |
||
| 30 | if (!$m || !$n) { |
||
| 31 | return $m === $n; |
||
| 32 | } |
||
| 33 | if ($m->val !== $n->val) { |
||
| 34 | return false; |
||
| 35 | } |
||
| 36 | array_push($stack, [$m->right, $n->right]); |
||
| 37 | array_push($stack, [$m->left, $n->left]); |
||
| 38 | } |
||
| 39 | |||
| 40 | return true; |
||
| 41 | } |
||
| 43 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.