I am trying to figure out how to make an object creation fail for ease
of error handling. Oddly, I can't work out how to do it.
Here's a reduced code sample of how I hoped it would work, but it
doesn't:
class Thing {
var $error;
function Thing() {
return 0;
}
}
if (!$theThing = new Thing()) {
echo "Couldn't create the thing -" . $thing->error;
}
I guess I could set $this to false instead of returning 0. But then I
wouldn't get the benefit of the error message, unless I echoed it,
which I don't like to do in classes.
Any good way to do this?
of error handling. Oddly, I can't work out how to do it.
Here's a reduced code sample of how I hoped it would work, but it
doesn't:
class Thing {
var $error;
function Thing() {
return 0;
}
}
if (!$theThing = new Thing()) {
echo "Couldn't create the thing -" . $thing->error;
}
I guess I could set $this to false instead of returning 0. But then I
wouldn't get the benefit of the error message, unless I echoed it,
which I don't like to do in classes.
Any good way to do this?
Comment