Connecting Tech Pros Worldwide Help | Site Map

How to define a member variable?

Bruce W...1
Guest
 
Posts: n/a
#1: Jul 17 '05
PHP barfs (on line 3) when I define a member variable like this:

class Foo()
{
$num;

function DoSomething()
{
$num = 2 + 3;

}
}

I want to do this so I can access if from another function. How can
this be done?

Thanks for your help.
Tom Thackrey
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How to define a member variable?



On 14-Oct-2003, "Bruce W...1" <bruce@noDirectEmail.com> wrote:
[color=blue]
> PHP barfs (on line 3) when I define a member variable like this:
>
> class Foo()
> {
> $num;
>
> function DoSomething()
> {
> $num = 2 + 3;
>
> }
> }[/color]

class Foo
{
var $num;
function DoSomething()
{
$this->num = 2+3;
}
}

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Matthias Esken
Guest
 
Posts: n/a
#3: Jul 17 '05

re: How to define a member variable?


"Bruce W...1" <bruce@noDirectEmail.com> schrieb:
[color=blue]
> PHP barfs (on line 3) when I define a member variable like this:
>
> class Foo()
> {
> $num;
>
> function DoSomething()
> {
> $num = 2 + 3;
>
> }
> }[/color]

The syntax has to be like that:

class Foo() {
var $num;

function DoSomething() {
$this->num = 2 + 3;
}
}


The documentation is here:
http://www.php.net/manual/en/language.oop.php

Regards,
Matthias
Pedro
Guest
 
Posts: n/a
#4: Jul 17 '05

re: How to define a member variable?


Bruce W...1 wrote:[color=blue]
>PHP barfs (on line 3) when I define a member variable like this:
>
>class Foo()
>{
> $num;[/color]
[...]


maybe

class Foo()
{
var $num;
// ...
}

will do the trick?


--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Bruce W...1
Guest
 
Posts: n/a
#5: Jul 17 '05

re: How to define a member variable?


Tom Thackrey wrote:[color=blue]
>
> On 14-Oct-2003, "Bruce W...1" <bruce@noDirectEmail.com> wrote:
>[color=green]
> > PHP barfs (on line 3) when I define a member variable like this:
> >
> > class Foo()
> > {
> > $num;
> >
> > function DoSomething()
> > {
> > $num = 2 + 3;
> >
> > }
> > }[/color]
>
> class Foo
> {
> var $num;
> function DoSomething()
> {
> $this->num = 2+3;
> }
> }
>
> --
> Tom Thackrey
> www.creative-light.com
> tom (at) creative (dash) light (dot) com
> do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)[/color]

===============================================

That seems to work. Thanks guys!
Closed Thread