473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Jul 17 '05 #1
4 4555

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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Leo | last post by:
I have a member function in this class, which needs a variable to keep track its status. Thus I used a static member variable. But I encounter a "unresolved external variable" error during...
10
by: Fred Ma | last post by:
Are there any reasons that would make it bad for C++ to allow simultaneous declaration and initilization of member data? Current way: ------------ class DerivedClass : BaseClass { { enum {...
4
by: Serge | last post by:
Hi, I have no problem creating a static member variable with integers, etc but when I try the same with a vector then I always get linker errors that the static member variable is unknown...
2
by: John Ratliff | last post by:
I'm having issues with forward declarations and possibly member variables. Can you declare a member variable and pass it parameters. class x { private: y obj(this); } Is that valid? I'm...
0
by: Desmond Bean | last post by:
I have an application with MFC extension DLL's with dialog's both in the main app and in the DLL's. Apart from care in the resource Id specification it works fine using classwizard in Vc 6, allowing...
1
by: Gary Wessle | last post by:
hi I have a design problem with this code, it is suppose to take a space delimited data file file_info x( f ); //f is a text file provided below and return the column of choice vector<stringbb...
13
by: yanlinlin82 | last post by:
I'd like to write all code of a class in only header file. But when there is any static member varia ble, I have to define it in cpp file, not the header file. Otherwise, the static member variable...
1
by: Immortal Nephi | last post by:
How can I modify member variable inside class if member function has const like mem_Func(void) const. Please do not offer the keyword -- mutable. I want to know if keyword -- const_cast can be...
3
by: NvrBst | last post by:
I'd like to do something like this but having a problem with the proper syntax in the constructor, maybe someone knows the correct syntax? ---MyClass.h--- #ifndef MYCLASS_H_ #define MYCLASS_H_...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.