Re: Exceptions and Errors

From: Date: Thu, 15 Apr 2004 05:36:46 +0000
Subject: Re: Exceptions and Errors
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  Groups: php.internals 
Request: Send a blank email to internals+get-9161@lists.php.net to get a copy of this message
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

« previous php.internals (#9161) next »