Re: Possible for class to return boolean?
wswilson schreef:
> Suppose I have:
>
> class A {
> function __construct() {
> $this->val = true;
> }
> }
>
> $a = new A();
>
> if ($a) {
> echo 'some text';
> }
>
> When I test "if ($a)", I want the class A to respond with the value of
> $this->val, which is true at the moment.
>
> Is this possible?
$a is an instance of your class, not a boolean.
So don't care if it is possible, care how OOP works. :-)
In your example you only populate some instance variable named val with
value true. $a will never return that unless you ask it to.
Regards,
Erwin Moller
|