Re: [PHP-DEV] Class constructor behaviour

2015-01-19 Thread Ferenc Kovacs
On Mon, Jan 19, 2015 at 6:04 PM, Michael Wallner wrote: > > On 19 Jan 2015 12:30, "Ferenc Kovacs" wrote: > > > > On Mon, Jan 19, 2015 at 6:41 AM, Stanislav Malyshev > > > wrote: > > > > > Hi! > > > > > > > This is pretty horrible and should be fixed by making sure that > > > > > > I don't see w

Re: [PHP-DEV] Class constructor behaviour

2015-01-19 Thread Michael Wallner
On 19 Jan 2015 12:30, "Ferenc Kovacs" wrote: > > On Mon, Jan 19, 2015 at 6:41 AM, Stanislav Malyshev > wrote: > > > Hi! > > > > > This is pretty horrible and should be fixed by making sure that > > > > I don't see why it's so horrible. In fact, handling null is easier than > > handling exception

Re: [PHP-DEV] Class constructor behaviour

2015-01-19 Thread Rowan Collins
Tony Marston wrote on 19/01/2015 09:54: You are forgetting one minor thing - an object may be instantiated from a piece of procedural code. In fact the very first object can only be instantiated from procedural code. I'm not sure what you mean by the second sentence here; which is the "ver

Re: [PHP-DEV] Class constructor behaviour

2015-01-19 Thread Ferenc Kovacs
On Mon, Jan 19, 2015 at 6:41 AM, Stanislav Malyshev wrote: > Hi! > > > This is pretty horrible and should be fixed by making sure that > > I don't see why it's so horrible. In fact, handling null is easier than > handling exception (and faster too, probably). Many functions that try > to create o

Re: [PHP-DEV] Class constructor behaviour

2015-01-19 Thread Tony Marston
"Rowan Collins" wrote in message news:CALKiJKqpk7X0yn0d_PWOKU1S7m156dF7865aLCP5dLF=q39...@mail.gmail.com... On 18 January 2015 at 11:28, Tony Marston wrote: "Andrea Faulds" wrote in message news:23490588-0131-4B0F-A7AA- c9c8c7666...@ajf.me... <> You are forgetting one minor thing - an

Re: [PHP-DEV] Class constructor behaviour

2015-01-18 Thread Peter Cowburn
On 19 January 2015 at 05:48, Stanislav Malyshev wrote: > Hi! > > > 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 ev

Re: [PHP-DEV] Class constructor behaviour

2015-01-18 Thread Stanislav Malyshev
Hi! > 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. Why it is d

Re: [PHP-DEV] Class constructor behaviour

2015-01-18 Thread Stanislav Malyshev
Hi! > This is pretty horrible and should be fixed by making sure that I don't see why it's so horrible. In fact, handling null is easier than handling exception (and faster too, probably). Many functions that try to create objects return null or false when unable to. Of course, we could change it

Re: [PHP-DEV] Class constructor behaviour

2015-01-18 Thread Rowan Collins
On 18 January 2015 at 11:28, Tony Marston wrote: > "Andrea Faulds" wrote in message news:23490588-0131-4B0F-A7AA- > c9c8c7666...@ajf.me... > >> >> Hi François, >> >> On 17 Jan 2015, at 15:37, François Laupretre >>> wrote: >>> >>> I would prefer deciding that returning null is the standard way

Re: [PHP-DEV] Class constructor behaviour

2015-01-18 Thread Tony Marston
"Andrea Faulds" wrote in message news:23490588-0131-4b0f-a7aa-c9c8c7666...@ajf.me... Hi François, On 17 Jan 2015, at 15:37, François Laupretre wrote: I would prefer deciding that returning null is the standard way for a constructor to inform the PHP core that the object creation failed (f

Re: [PHP-DEV] Class constructor behaviour

2015-01-18 Thread Matteo Beccati
Hi, On 18/01/2015 09:31, Sebastian Bergmann wrote: Several classes in PHP return null when there is a problem in the parameters passed to their constructor e.g. [...] Several constructors check the parameters that they are given.and then just give a warning when they are not acceptable. e.

Re: [PHP-DEV] Class constructor behaviour

2015-01-18 Thread Sebastian Bergmann
Am 17.01.2015 um 15:02 schrieb Dan Ackroyd: > class constructors PHP does not have class constructors (static method automatically invoked when a class is initialized). It only supports object constructors (method automatically invoked when an object is created). > Several classes in PHP

RE: [PHP-DEV] Class constructor behaviour

2015-01-17 Thread François Laupretre
> De : Andrea Faulds [mailto:a...@ajf.me] > > I don’t really agree here. For some reason we have this tradition of not using > exceptions for “procedural” stuff. That sort of makes sense for functions, but > classes are “OOP” and therefore I don’t see a good reason why they > shouldn’t throw except

Re: [PHP-DEV] Class constructor behaviour

2015-01-17 Thread Marco Pivetta
On 17 January 2015 at 16:37, François Laupretre wrote: > > De : Dan Ackroyd [mailto:dan...@basereality.com] > > > > 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

Re: [PHP-DEV] Class constructor behaviour

2015-01-17 Thread Dan Ackroyd
On 17 January 2015 at 16:04, Rowan Collins wrote: > The difference is that AFAIK all the exceptions returned by OOP extensions > right now are of classes specific to that extension, whereas this would be a > global engine-thrown exception. Sorry - I wasn't clear. I didn't mean they should throw

Re: [PHP-DEV] Class constructor behaviour

2015-01-17 Thread Rowan Collins
On 17 January 2015 at 15:43, Andrea Faulds wrote: > Hi François, > > > On 17 Jan 2015, at 15:37, François Laupretre > wrote: > > > > 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

Re: [PHP-DEV] Class constructor behaviour

2015-01-17 Thread Andrea Faulds
Hi François, > On 17 Jan 2015, at 15:37, François Laupretre wrote: > > 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 er

RE: [PHP-DEV] Class constructor behaviour

2015-01-17 Thread François Laupretre
> De : Dan Ackroyd [mailto:dan...@basereality.com] > > 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=1192637480