Should I use `if ($ a! = NULL)` or `if ($ a! == NULL)` to control the program flow?

This is perhaps the main question that needs to be answered, but I am wondering about performance issues regarding the use of PHP if it is identical !==against if equal !=for flow control.

Consider the following trivial PHP function:

<?php
 function test_json($json = NULL) {
  if ($json != NULL) {
   echo 'You passed some JSON.';
  } else {
   echo 'You failed to pass any JSON.';
  }
 }
?>

In terms of performance, is it preferable to use if identical ( !==) to prevent iteration of PHP through variable types, trying to find the right comparison?

I assume it !==compares the types of variables first, and if that fails, does it immediately return FALSE? I used !=since PHP3 is almost like a reflex. Now that I am working on much more complex computing projects, considerations of minimal performance are becoming increasingly serious problems.

Other comments on streamlining optimization are of course welcome!

+5
source share
2 answers

I have not conducted any performance tests in free and strict matching operations, but for what you are trying to do, I would recommend something like

if (!is_null($json)) {
    do_stuff()
}

Further information on is_null()at http://www.php.net/manual/en/function.is-null.php

EDIT: php- I, , , , === , ==, , is_null(). , " === NULL is_null 250 . , ". . , , , , .

+7
0

All Articles