Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75218 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20290 invoked from network); 3 Jul 2014 11:30:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jul 2014 11:30:12 -0000 Authentication-Results: pb1.pair.com header.from=xen@dds.nl; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=xen@dds.nl; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dds.nl from 85.17.251.144 cause and error) X-PHP-List-Original-Sender: xen@dds.nl X-Host-Fingerprint: 85.17.251.144 smtp.dds.nl Linux 2.6 Received: from [85.17.251.144] ([85.17.251.144:55004] helo=montblanc.dds.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/FF-47713-3CE35B35 for ; Thu, 03 Jul 2014 07:30:11 -0400 Received: from swan.dds.nl (swan.dds.nl [85.17.251.134]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by montblanc.dds.nl (Postfix) with ESMTPS id 23F1B6E0755; Thu, 3 Jul 2014 13:17:32 +0200 (CEST) Date: Thu, 3 Jul 2014 13:30:07 +0200 (CEST) To: Lazare Inepologlou cc: "internals@lists.php.net" In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=UTF-8 X-Virus-Scanned: clamav-milter 0.97.8 at montblanc X-Virus-Status: Clean Subject: Re: [PHP-DEV] not_null function From: xen@dds.nl (Xen) 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.