Hi Max!
--- you wrote:
> Hello sam1600,
>
> Wednesday, January 10, 2001, 6:42:58 AM, you wrote:
>
> sic> What in the world is reason for declaring the following in the class?:
> sic> var $somevar;
> sic> I see no reason, and no differences if I don't declare: var $somevar;
>
> Classes are intended to be structured data storage. You should define
> a structure of the class before using the class.
> You can set the value of the $somevar anytime later, when using an
> object of class a.
> $d->somevar = true;
> and the next call to $d->b() will print nothing.
> But you won't be able to assign a value to $somevar, if it is not
> declared in the class.
This does not appear to be true. With error reporting set to max, and the
variables not defined in the class ( $somevar,$somevar2 and $somevar3 ),
the following will echo out:
Not set
empty
value of somevar2
value of somevar3
class a {
function b(){
if (!isset($this->somevar))
echo "Not set<br>";
if (empty($this->somevar))
echo "empty<br>";
}
}
$d = new a;
$d->b();
$d->somevar2 = "value of somevar2<br>";
$d->somevar3 = "value of somevar3<br>";
echo $d->somevar2;
echo $d->somevar3;
>
> sic> Maybe a better question is what will break if I do not declare
> sic> my vars in my class definition?
>
> the method b() of the class a will break if you don't declare $somevar
> in the class definition. In the string "if (!isset($this->somevar))"
> it would throw an error saying that you have no variable named 'somevar' in
> you class.
This does not appear to be true either, see above.
Thanks,
Sam
I'm using php4.0
----------------------------------------------------------------
Get your free email from AltaVista at http://altavista.iname.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]