Re: wacky object idea
| From: | Stig S. Bakken | Date: | Mon, 28 Aug 2000 08:39:46 +0000 |
| Subject: | Re: wacky object idea | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-30934@lists.php.net to get a copy of this message | ||
Chuck Hagenbuch wrote:
>
> How hard would it be to add a special toBoolean() method to objects, such
> that if you defined that method, the result would be used as the value of
> the object in a comparison.
>
> This would let us define PEAR_Exception and friends to return false, letting
> you just do if ($obj->method()) and rely on an exception to trip failure...
I'd go further than that and say it could be this way of all scalar
types:
class Test {
function toString() {
return "42";
}
function toDouble() {
return 42.0;
}
function toLong() {
return 42;
}
function toBool() {
return true;
}
}
Some PEAR code happens to already define toString().
- Stig