Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9450 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47622 invoked by uid 1010); 21 Apr 2004 10:03:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 47568 invoked from network); 21 Apr 2004 10:03:19 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 21 Apr 2004 10:03:19 -0000 Received: from [192.168.1.3] (p508EA078.dip.t-dialin.net [80.142.160.120]) by shiva.mind.de (Postfix) with ESMTP id DE67197C5F; Wed, 21 Apr 2004 12:03:17 +0200 (CEST) Date: Wed, 21 Apr 2004 12:03:21 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1921263076812.20040421120321@marcus-boerger.de> To: internals@lists.php.net Cc: Andi Gutmans , Zeev@zend.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: typehinting and NULL From: helly@php.net (Marcus Boerger) Hello Andi, Zeev, internals, after readin the PHP articles on PHP5 and the rerequested typehinting for arrays i once again thought about typehints and NULL. At the moment typehints allow NULL always. That is complete nonsense because NULL doesn't pass any instance-of check. And in general there is only one operation that leagally returns true when working with NULL values. That is NULL === NULL. In php NULL == NULL simply returns true because NULL equals zero. Hence: $ php -r 'var_dump(NULL == NULL);' bool(true) $ php -r 'var_dump(NULL == 0);' bool(true) $ php -r 'var_dump(NULL === NULL);' bool(true) AND: $ php -r '$o=new stdClass; var_dump($o instanceof stdClass);' bool(true) $ php -r 'var_dump(NULL instanceof stdClass);' bool(false) At least we must find a way to decide whether or not NULL should be allowed NULL. Yes enforcing NOL NULL would make too many people complain they cannot pass a NULL by ref to have it returned as an instance of the class - though reconsider your code should be the answer here. Looking up the discussions about the issue we already had a solution for this from Zeev. function allowingNULL(object $val = NULL) function preventNULL(object $val) any thoughts? Just to stress out: The current situation doesn't respect generally accepted inheritance rules. Best regards, Marcus