-
PHP 4: static
I don't know if PHP 4 supports static but I need help on achieving this or workaround on having something like
Code:
<?php
class test {
static $a;
function b() {
if (!isset(test::$a)) {
test::$a = "hello world";
}
return test::$a;
}
}
echo test::b();
Thanks.
-
Re: PHP 4: static
Static is supported in PHP4. Access static variables using the scope resolution operator:
-
Re: PHP 4: static
I've got PHP Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in C:\Program Files\Apache Group\Apache2\htdocs\tests\_debug_tmp.php on line 6 with
Code:
<?php
class test {
var $a;
function b() {
if (!isset(test::$a)) {
test::$a = "hello world";
}
return test::$a;
}
}
echo test::b();
?>
:(
-
Re: PHP 4: static
I haven't quite worked out why you get a parse error but you replaced 'static' with 'var' which means you can no longer access $a statically.
-
Re: PHP 4: static
static $a; has PHP Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in C:\Program Files\Apache Group\Apache2\htdocs\tests\_debug_tmp.php on line 3 :( I think there's no reserved keyword (for modifier) static for PHP 4. This is PHP 4 btw, pen. Thanks.
-
Re: PHP 4: static
Sorry, I don't have PHP 4 handy and so posted under the assumption that visualAd was correct. I'll remember not to do that in future. :D
There is a solution in the manual for simulating static fields in PHP 4.
http://au3.php.net/manual/en/keyword...ayim.php#58724
Hope that helps.
-
Re: PHP 4: static
-
Re: PHP 4: static
I seem to remember using static variables in PHP. :confused:
-
Re: PHP 4: static
But only in functions .... Sorry :blush: