Re: exit in class constructor crashes
| From: | Daniel Convissor | Date: | Mon, 31 Jul 2000 13:22:37 +0000 |
| Subject: | Re: exit in class constructor crashes | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9155@lists.php.net to get a copy of this message | ||
YO YO YO!
Daniel Convissor wrote:
>
> Got an answer! Gee, I've had a lot of threads here, and elsewhere, in which
> I'm having a dialogue with myself. Anyway...
Yet another missive for you.
Last night, I posted an answer for ways to exit() from a constructor
function. Since then I've come up with the solution.
Earlier, Dennis asked a general question about the ability to use "return" to
break out of a function. I thought about it's use for my needs. But, I
overlooked it initially, because the exit() I'm issuing comes in a
sub-function called by the constructor function. Further thought led me to
the idea to have the sub-function return some value, which I'll evaluate in
the constructor function. If the value indicates a problem in the
sub-function, I'll then call call a "return" in the constructor function.
Ding!
Far more elegant than my initial answer...
<?php
class ConstructorExit {
function ConstructorExit() {
echo "Welcome to the Constructor Exit Test.";
if ( $this->SomeSubFunction() ) {
# Sub function says there's a problem.
return;
}
echo "<br>I don't want this to be seen.";
}# End of function ConstructorExit
function SomeSubFunction() {
echo "<br>Well, you're now in the sub-function.";
return 1;
echo "If you see this, the sub-function didn't return.";
}# End of SomeSubFunction
}# End of class ConstructorExit
$Post = new ConstructorExit;
?>
Wee haw!
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
More than just answers. Solutions. (SM)
http://www.analysisandsolutions.com/
4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409