Connecting Tech Pros Worldwide Help | Site Map

How to define a member variable?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:32 AM
Bruce W...1
Guest
 
Posts: n/a
Default How to define a member variable?

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, 12:32 AM
Tom Thackrey
Guest
 
Posts: n/a
Default 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, 12:32 AM
Matthias Esken
Guest
 
Posts: n/a
Default 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, 12:32 AM
Pedro
Guest
 
Posts: n/a
Default 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, 12:33 AM
Bruce W...1
Guest
 
Posts: n/a
Default 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!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.