By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,746 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,746 IT Pros & Developers. It's quick & easy.

How to define a member variable?

P: 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.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

On 14-Oct-2003, "Bruce W...1" <br***@noDirectEmail.com> wrote:
PHP barfs (on line 3) when I define a member variable like this:

class Foo()
{
$num;

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

}
}


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 ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2

P: n/a
"Bruce W...1" <br***@noDirectEmail.com> schrieb:
PHP barfs (on line 3) when I define a member variable like this:

class Foo()
{
$num;

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

}
}


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
Jul 17 '05 #3

P: n/a
Bruce W...1 wrote:
PHP barfs (on line 3) when I define a member variable like this:

class Foo()
{
$num;

[...]
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.
Jul 17 '05 #4

P: n/a
Tom Thackrey wrote:

On 14-Oct-2003, "Bruce W...1" <br***@noDirectEmail.com> wrote:
PHP barfs (on line 3) when I define a member variable like this:

class Foo()
{
$num;

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

}
}


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 ja*********@willglen.net (it's reserved for spammers)


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

That seems to work. Thanks guys!
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.