Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9161 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77442 invoked by uid 1010); 15 Apr 2004 05:36:56 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 77415 invoked from network); 15 Apr 2004 05:36:55 -0000 Received: from unknown (HELO tc.ma.cx) (82.82.33.253) by pb1.pair.com with SMTP; 15 Apr 2004 05:36:55 -0000 Received: from localhost (schnuffel [127.0.0.1]) by tc.ma.cx (Postfix) with ESMTP id BB58A1EFF7; Thu, 15 Apr 2004 07:36:54 +0200 (CEST) Received: from tc.ma.cx ([127.0.0.1]) by localhost (schnuffel.thieso.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 29631-09; Thu, 15 Apr 2004 07:36:44 +0200 (CEST) Received: from [192.168.254.5] (titan.w.thieso.net [192.168.254.5]) by tc.ma.cx (Postfix) with ESMTP id C51861B3DF; Thu, 15 Apr 2004 07:36:44 +0200 (CEST) In-Reply-To: <43693637937.20040414215314@marcus-boerger.de> marcus-boerger.de> Mime-Version: 1.0 (Apple Message framework v613) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-ID: Content-Transfer-Encoding: 7bit Cc: Thies C.Arntzen , Christian Schneider , PHP Internals Date: Thu, 15 Apr 2004 07:36:46 +0200 To: Marcus Boerger X-Mailer: Apple Mail (2.613) X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at thieso.net Subject: Re: [PHP-DEV] Exceptions and Errors From: thies@thieso.net (Thies C . Arntzen) Am 14.04.2004 um 21:53 schrieb Marcus Boerger: >> Personally I'd much prefer a way of returning a value from a >> constructor, i.e. to be able to 'return null;' or a similar language >> construct so I could do 'if ($db = new SQLiteDatabase)' >> It would also mean that I would run into a 'calling method on a >> non-object' error if I don't check it (which is fine). > > In no language i know (c++, delphi, java as the popular ones) a ctor > can return a value especially not it's own value. The problem is that > when the ctor is called the object is already created. For most > languages > that means some memory has been allocated and for php overloaded > objects > like the SQLite class it also means that the memory has been > initialized. > > Now in PHP 4 there was the ugly trick of setting "$this=NULL". > i'm sure ZE2 can be tricked to support "return NULL" from a constructor so that: $a = new bla(); if (! $a) ... if ctors are the only place that *cannot* life without exceptions it would be well worth *fixing* (yes, i said fix), as adding "understanding exceptions" to the list of pre-requisites for learning/using php would just be a poor decision looking at what made php as popular as it is today. thies