Connecting Tech Pros Worldwide Help | Site Map

How to define a member variable?

  #1  
Old July 17th, 2005, 01:32 AM
Bruce W...1
Guest
 
Posts: n/a
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.
  #2  
Old July 17th, 2005, 01:32 AM
Tom Thackrey
Guest
 
Posts: n/a

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)
  #3  
Old July 17th, 2005, 01:32 AM
Matthias Esken
Guest
 
Posts: n/a

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
  #4  
Old July 17th, 2005, 01:32 AM
Pedro
Guest
 
Posts: n/a

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.
  #5  
Old July 17th, 2005, 01:33 AM
Bruce W...1
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Don't want to define derived class? Immortal Nephi answers 3 September 3rd, 2008 08:25 PM
About static member variable yanlinlin82@gmail.com answers 13 October 3rd, 2007 02:25 PM
member variable wizard not available in MFC extension DLL Desmond Bean answers 0 November 17th, 2005 02:29 PM
unresolved external symbol linker error with a vector which is a static member variable Serge answers 4 July 23rd, 2005 12:01 AM