FAQ

On 17 January 2015 at 16:37, François Laupretre wrote:

De : Dan Ackroyd

This is pretty horrible and should be fixed by making sure that
constructors either return an object or throw an exception.
Additionally the exception policy for core (that was previously
discussed here: http://marc.info/?t=119263748000001&r=1&w=2 ) should
be updated so that any constructor returning NULL is considered a bug,
no matter what the ini settings are.
I would prefer deciding that returning null is the standard way for a
constructor to inform the PHP core that the object creation failed (for any
reason). This would be trapped by the core and cause a catchable fatal
error.
A constructor that fails is a hard failure (factory method failed to
produce the expected value), and is an exceptional case that can or cannot
be handled (via catch).
It's not just a failed operation (expected to eventually fail), but
something really went wrong, badly.

An exception fits perfectly in this case.

Additionally, it makes no sense to have inconsistent behavior between
internal classes and userland classes: it is currently impossible for a
userland class to have the `new` operator producing an object that is not
an instance of the class after that operator.

It feels weird, from a user perspective, to have `new` producing non-object
values.

The general feeling when dealing with cases such as PDO's constructor is
"WAT?!".

Therefore gogogo Danack!

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 19 | next ›
Discussion Overview
groupphp-internals @
categoriesphp
postedJan 17, '15 at 2:02p
activeJan 19, '15 at 5:37p
posts19
users12
websitephp.net

People

Translate

site design / logo © 2019 Grokbase