473,378 Members | 1,617 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,378 software developers and data experts.

PHP5 and static functions/vars

Hi,
I need to add a string to a class var, but it doesn´t work though I read it
is a new feature in PHP5.
This is my code:

class Huh{
static $message;

public static function addMessage($message){
Huh::message += $message."<BR>\n";
}
}

What´s wrong?

Greets, Carsten
Jul 16 '05 #1
4 13322
Carsten B. wrote on Tuesday 29 July 2003 00:41:
Hi,
I need to add a string to a class var, but it doesn´t work though I read
it is a new feature in PHP5.
This is my code:

class Huh{
static $message;

public static function addMessage($message){
Huh::message += $message."<BR>\n";
}
}

What´s wrong?


I am not sure what you are trying to achieve with this. Are you trying to
modify a class definition?

You can't make non-instance calls like that.

I am guessing what you want to do is use object's method to change/update
the property; if so, you need to create an instance of the object. And, in
that case, don't define those methods and properties as static.

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 16 '05 #2
Tuesday 29 of July 2003 11:13, Zurab Davitiani wrote in comp.lang.php:

the property; if so, you need to create an instance of the object. And, in
that case, don't define those methods and properties as static.


You don't need to create an instance of an object ... the following works
for me (tested right now ;):

<?php

class Test {

static $testingval;

public static function setVal($val){

test::$testingval += $val;
echo "val: " . test::$testingval . "<BR>";

}

}

test::setVal(1);
test::setVal(4);
test::setVal(8);

?>

with results:

val: 1
val: 5
val: 13

on `official` PHP5b1

regards!

-robert-

--
Robert Jirik
[mailto:robert(at)aristoteles(dot)xhaven(dot)net]
public PGP key: http://xhaven.net/robert/pgp_key.asc
-
"In the first place, God made idiots. That was for practice.
Then he made school boards"
-- Mark Twain

Jul 16 '05 #3


Carsten B. wrote:
Hi,
I need to add a string to a class var, but it doesn´t work though I read it
is a new feature in PHP5.
This is my code:

class Huh{
static $message;

public static function addMessage($message){
Huh::message += $message."<BR>\n";
}
}

What´s wrong?

Greets, Carsten


Simple syntax problem:

Huh::$message += $message;

Jul 16 '05 #4
"Carsten B." <sp*****@web.de> schrieb:
Huh::message += $message."<BR>\n";


Shouldn't you use a "." as a string concatenation operator?

Matthias
Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: porneL | last post by:
How do I use static functions/properties with inheritance? I've found it very problematic. class Foo { static function A() {/* ??? */::B(); } static function B() {echo 'Foo';} }; class...
2
by: [Mystic] | last post by:
Hi I was just wondeirng how they work now, esspically regarding functions and return values. Do functions pass return by value or reference? Concidering the following: public static...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
5
by: voronwae | last post by:
Hi folks. Either I'm missing something really obvious (most likely) or I'm missing something really subtle. I've been building up a machine as an IMP webmail server, with php 5.1.2, cyrus-sasl,...
10
by: John A Grandy | last post by:
Say I have Class1 which contains static Class2 var1 = new Class2(); Is Class2 constructor code only executed if var1 is referenced in the code-execution path ? Or is Class2 constructor code...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
5
by: The Big One | last post by:
8-7-2008 Hello, Our hosting provider has changed his server to PHP5. I have a PHP file that normaly gives the custumor an email, and i get one mail. Now the server has changed i only get my...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.