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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to