Computing.Net > Forums > Web Development > PHP class variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP class variables

Reply to Message Icon

Name: nexterday
Date: January 11, 2006 at 19:49:23 Pacific
OS: winXP
CPU/Ram: pentiumIV/1GB
Comment:

im trying to get a class to work in php (v4.4.1 on a linux server which i've been using for years), with public, private and static instance variables. i can use
var $varname = 'hello';

to define just a normal instance variable (public) but for some reason if i say
public $varname = 'hello';
it will crash with

parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'

that happens if i try public, private, static, protected, or even public var $variable...the same thing happens if i try public function fname(){

all of this is inside the class MyClass
{ } brackets...and the class will function...almost normally if i take out all public, private, etc. types.
however when it DOES work, all my
var $var1;
var $var2;
have the same reference, so if i change one, they all change.
ie
$var1 = "hello";
$var2 = "there";
echo $var1 . $var2;
will output "therethere"
any help on either of these topics is greatly appriciated.



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: January 11, 2006 at 22:13:50 Pacific
Reply:

All those keywords are valid in PHP5, not version 4.x. There's no such thing as public, private, or static members in PHP 4.

-SN


0

Response Number 2
Name: zerofunk
Date: January 13, 2006 at 10:35:45 Pacific
Reply:

Yeah, an to add to that, I would not use php5 untill it had gotten a little older. Never use a #.0 version, it might have issues that have not been worked out.

Siggy: Always check the manual first, Google helps too.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP class variables

PHP-Class, object, method www.computing.net/answers/webdevel/phpclass-object-method/3432.html

E-mail Piping Format (PHP) www.computing.net/answers/webdevel/email-piping-format-php/1072.html

Parse Email Headers using PHP www.computing.net/answers/webdevel/parse-email-headers-using-php/3248.html