Afficher un message
Vieux 27/03/2008, 16h12   #2
Erwin Moller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
 
Page generated in 0,04629 seconds with 9 queries