Re: php/mysql object id question..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Oliver Grätz wrote:
3. Yes. One can abuse exceptions to return something in a constructor.
   Just another argument against exceptions ;-) OK, it's unorthodox,
   if you absolutely need to do that, do it and tell nobody *g*.

This is not "abusing" exceptions. If you throw an exception then the expected behaviour should be that the following code should not be executed [1].

Throwing an exception inside a constructor will prevent the object from being created. It will not allow you to "return something" of your choice -- I haven't tested but I would expect that the variable you were setting as the object would either remain unset or would be set to NULL.

IMHO, this is exactly how it should be, definitely not "unorthodox", and I'm not too sure why you said "just another argument against exceptions" (apart from perhaps a lack of understanding) as exceptions are a very useful feature in any language.

[1] http://php.net/exceptions
--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux