Re: not_null function
| From: | Xen | Date: | Thu, 03 Jul 2014 11:30:07 +0000 |
| Subject: | Re: not_null function | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75218@lists.php.net to get a copy of this message | ||
On Thu, 3 Jul 2014, Lazare Inepologlou wrote:
Well, there is a better alternative: if ( $x === null ) .... if ( $x !== null ) .... This syntax has also the advantage that it is marginally faster as there is neither a function call nor a negation involved. :)This is semantically wrong because a programmer testing for not-null is not testing for the negation of is-null. That is because null is not really a value. It is the absence of value. The absence of any value is not the negation of the presence of a ....value that doesn't exist. In the programmer's mind, "null" CAN have a value indeed but in that case he has picked it himself. In that case it would be semantically sound for him to check ($a == null). But most of the time you don't want to know whether something is null, you want to know whether something has any value other than null (whether it has a value at all). Therefore, usually, checking "$a != null" is not entirely meaningful because you don't really care about that value you are mentioning, it has no meaning to you. This is what makes it meaningless. All of the terms in a sentence must have meaning for the entire sentence to have full meaning. The absence of any value is a meaningful concept that ought to be directly testable. But you test it by asking for the /presence/ of any value. And if you *did* want to test for the absence, you would ask "does it have any value?" Just try to say this in English: "doesn't the cup have anything in it?" or "does the cup not have anything in it?" You can see the meaning changes completely from what you intend. In natural language you don't do that. You say "/IS THERE A PRESENCE/" or "is there a contents"? You don't ask for the negation of the negative, because it has a very different meaning.