Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10574 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65569 invoked by uid 1010); 17 Jun 2004 19:00:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 65544 invoked from network); 17 Jun 2004 19:00:40 -0000 Received: from unknown (HELO mx.thebrainroom.net) (65.200.24.98) by pb1.pair.com with SMTP; 17 Jun 2004 19:00:40 -0000 Received: by mx.thebrainroom.net (Postfix, from userid 517) id 9C07514880C4; Thu, 17 Jun 2004 12:00:12 -0700 (PDT) Received: from BAUMBART (pD95F8F61.dip.t-dialin.net [217.95.143.97]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by mx.thebrainroom.net (Postfix) with ESMTP id 5ABA214880C2; Thu, 17 Jun 2004 11:59:58 -0700 (PDT) Date: Thu, 17 Jun 2004 20:58:26 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <4210590559.20040617205826@marcus-boerger.de> To: Ray Hilton Cc: Christian Schneider , mike@php.net, internals@lists.php.net In-Reply-To: <40D19B3E.4030802@memefeeder.com> References: <20040615112747.27402.qmail@pb1.pair.com> <40CEDECA.9040600@cschneid.com> <40D05892.6090804@memefeeder.com> <913185304.20040616211716@marcus-boerger.de> <40D19B3E.4030802@memefeeder.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on jc.thebrainroom.net X-Spam-Status: No, hits=0.8 required=5.0 tests=PRIORITY_NO_NAME autolearn=no version=2.63 X-Spam-Level: X-TBR-Filter: Virus scanned and defanged Subject: Re: [PHP-DEV] Re: ClassHints and NULL From: helly@php.net (Marcus Boerger) Hello Ray, Thursday, June 17, 2004, 3:23:10 PM, you wrote: > I understand your point, however, this is the way that other languages > behave and its a feature that i consider to be very necessary and > timesaving. In this case PHP behaves like Java very only one pass by reference is allowed. You compare this to C++ and others where pointers exist. And obviously you can set a pointer to NULL. BUT we are talking of pass by reference or pass by value since a PHP pointer is a '$$name' construct. > My understanding was that Typehinting exists to save having > to do such if-else clauses all the time, since 99.9% of the time, you > will expect an object of a certain class or nothing at all. Exactly. And i don't want to have to write function bla(Classname $x) { if (!is_null($x)).... all the time. > The problem > here is that i need only to know that an argument is either an instance > of a class or null, nothing else, but removing the typehinting > effectively means any argument can be passed, and its not longer > enforced at a PHP level, but within my own code... and since this is > something that happens a lot, it seems a shame to loose this handy, > timesaving functionality. I don't think it is timesaving to have to write '!is_null()' all the time. And once again null is not an instance of any class. Last but not least we know already that a lot of people like to be able to handle both instanceof or null with typehints. But at the moment we have no solution that can go into PHP 5.0. However i am quite sure we will address this for 5.1. > Ray > and Marcus Boerger wrote: >>Hello Ray, >> >>Wednesday, June 16, 2004, 4:26:26 PM, you wrote: >> >> >> >>>Hi all, >>> >>> >> >>[....] >> >> - NOTHING stops you from passing NULL to functions. >> - Typhints are a shortcut for an 'instanceof'`test >> >> - now try NULL instanceof stdclass: >> >>php-cvs $ php -r 'var_dump(NULL instanceof stdclass);' >>bool(false) >> >>- what you probablywant is >>function bla($x) { >> if (is_null($x)) { >> // handle null >> } else if ($x instanceof whatever) { >> // handle instance >> } else { >> // handle error >> } >>} >> >>- if you look again you'll see that you are doing *three different* >> things in your code. Typehints have a different usage! >> >>best regards >>marcus >> >> >> -- Best regards, Marcus mailto:helly@php.net