Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Matthew Carter Newsgroups: comp.lang.php Subject: Re: OO PHP result of new if a constructor fails Date: Tue, 11 Nov 2014 12:01:27 -0500 Organization: Ahungry (http://ahungry.com) Lines: 79 Message-ID: <87d28twu1k.fsf@ahungry.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="7c986cd4736462de309a749b207746fe"; logging-data="24937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HAtXXAJdtohlMD0XPeyvw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:71iII8vNyBmBq+r5eV3lsPJ9AdA= sha1:niahFUMqvr1IE3w2Pld0o0B2cjI= Xref: csiph.com comp.lang.php:14535 "James Harris" writes: > "Jerry Stuckle" wrote in message > news:m3tc0l$8ic$1@dont-email.me... >> On 11/11/2014 10:56 AM, James Harris wrote: >> >> No, specifically - how can it fail? >> > > ... > >> Specifically, how would the constructor fail? >> >> I'm not trying to give you a hard time. > > Are you sure? .... :-( > >> You can't answer what happens >> in case of failure without understanding the failure itself. > > I think you may be talking about something else. I guess there are lots of > ways a constructor can fail: out of memory, no access to a resource, invalid > parameter value, incompatible parameters, disk IO error, network outage, > invalid credentials, faulty program etc etc. Without knowing the internals > of a particular constructor (not a good idea) your question about how that > constructor can fail cannot be answered. Even if it could the answer(s) > might change when a new version of that constructor is released. So there is > no way to sensibly enumerate all potential causes of failure and derive > findings from that. > > So rather than asking about a specific constructor I was looking to see if > there was a PHP rule that could always be applied. > > If that's not what you mean can you explain what you have in mind? I cannot > understand your meaning from what you have said so far. > > James > > Hi James, Please see/run the snippet: You will notice that $a is simply undefined (and if you do not have the try/catch block, you won't make it that far, as your uncaught exception will bubble up and terminate the script). Most things that would cause an aspect of php to 'fail' are just built in exceptions (or for something like divide by zero, a notice will be thrown but $a will still be the class instance). I'm not sure how else you could cause a construct to 'fail'. -- Matthew Carter (m@ahungry.com) http://ahungry.com