473,574 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use the keyword 'static' in PHP 4?

In the code below I'm getting a parse error on this line:

static $controllerForA ll = new McControllerFor All();

why does this give me a parse error? I'm running PHP 4.

function & getController($ callingCode=fal se) {
// 11-27-04 - we want to get the controllerForAl l variable, and we
want to make
// sure that it is always passed by reference. Rather than having
functions do
// something like this:
//
// global $controllerForA ll;
//
// we instead want them to use this function. This adds a wrapper to
the way we
// this variable and thus allows more flexibility in changing the
access later.
// After all, it may not remain in global space in future versions of
the
// software.

// 12-12-04 - we declare controllerForAl l to be static, therefore the
second time
// this function is called it should already exist.

if (is_object($con trollerForAll)) {
if ($callingCode) $controllerForA ll->setCallingCode ($callingCode);
return $controllerForA ll;
} else {
$controllerForA ll = & $GLOBALS["controllerForA ll"];
if (is_object($con trollerForAll)) {
if ($callingCode) $controllerForA ll->setCallingCode ($callingCode);
return $controllerForA ll;
} else {
if (class_exists(" McControllerFor All")) {
static $controllerForA ll = new McControllerFor All();
if (is_object($con trollerForAll)) {
if ($callingCode) $controllerForA ll->setCallingCode ($callingCode);

return $controllerForA ll;
} else {
echo "Awful sorry, we were looking for a software object called
'McControllerFo rAll' but we were unable to find it. The software
really, really needs it to work.";
}
} else {
echo "Awful sorry, we were looking for a software object called
'McControllerFo rAll' but we were unable to find it. The software
really, really needs it to work.";
}
}
}
}

Jul 17 '05 #1
3 2179
<lk******@geoci ties.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
In the code below I'm getting a parse error on this line:

static $controllerForA ll = new McControllerFor All();

why does this give me a parse error? I'm running PHP 4.

function & getController($ callingCode=fal se) {
// 11-27-04 - we want to get the controllerForAl l variable, and we
want to make
// sure that it is always passed by reference. Rather than having
functions do
// something like this:
//
// global $controllerForA ll;
//
// we instead want them to use this function. This adds a wrapper to
the way we
// this variable and thus allows more flexibility in changing the
access later.
// After all, it may not remain in global space in future versions of
the
// software.

// 12-12-04 - we declare controllerForAl l to be static, therefore the
second time
// this function is called it should already exist.

if (is_object($con trollerForAll)) {
if ($callingCode) $controllerForA ll->setCallingCode ($callingCode);
return $controllerForA ll;
} else {
$controllerForA ll = & $GLOBALS["controllerForA ll"];
if (is_object($con trollerForAll)) {
if ($callingCode) $controllerForA ll->setCallingCode ($callingCode);
return $controllerForA ll;
} else {
if (class_exists(" McControllerFor All")) {
static $controllerForA ll = new McControllerFor All();
if (is_object($con trollerForAll)) {
if ($callingCode) $controllerForA ll->setCallingCode ($callingCode);

return $controllerForA ll;
} else {
echo "Awful sorry, we were looking for a software object called
'McControllerFo rAll' but we were unable to find it. The software
really, really needs it to work.";
}
} else {
echo "Awful sorry, we were looking for a software object called
'McControllerFo rAll' but we were unable to find it. The software
really, really needs it to work.";
}
}
}
}


I believe that 'static' can only be used for non-computed values... so:

static $var = 1; // is ok
static $var = 1+1; // not ok

try this:

if (class_exists(" McControllerFor All")) {
$tmp = new McControllerFor All();
static $controllerForA ll = $tmp;
}
Check out this link...
http://us2.php.net/manual/en/languag...bles.scope.php

Norm
---
Avatar Hosting at www.easyavatar.com

Jul 17 '05 #2
Norman Peelman wrote:
<lk******@geoci ties.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
In the code below I'm getting a parse error on this line:

static $controllerForA ll = new McControllerFor All();

why does this give me a parse error? I'm running PHP 4.


You will have to do it in two steps:

static $controllerForA ll ;
$controllerForA ll = new McControllerFor All();
JW

Jul 17 '05 #3
Thanks. I seemed to have solved the problem by moving this line to the
top of the function:

static $controllerForA ll;
I guess it only runs the first time the function is called.

Jul 17 '05 #4

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

Similar topics

14
3180
by: lawrence | last post by:
To call I would do something like: $headline = McSelectJustOneField::callDatastore("cbHeadline"); Is this the correct use of the static keyword, to implement a Singleton design?
9
6351
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not necessary and it is not the practice in C++. Static keyword is useful inside struct, class, and function only unless you want to force local variable to be global variable so static is used. Do you...
5
16598
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining extern storage class: /****************************************************************** SOURCE FILE ONE...
16
15100
by: vaughn | last post by:
What is the 'this' keyeword for? If I'm filling a textbox, what's the difference between this.textbox1.Text = "my text"; and textbox1.Text = "my text"; ? I normally use it w/o the 'this'. Thanks.
14
2920
by: Zeng | last post by:
Would somebody know when we should seal a class? Shouldn't all classes be open up for inheritance? Thanks!
3
6640
by: Danny Din | last post by:
Hi, I have the following code public class Class1 { public Class1()
54
2681
by: Sahil Malik [MVP] | last post by:
What the heck - I can't find it. A bit shocked to see it missing though. So "Does VB.NET have the yield keyword, or any equivalent of it" ? -- - Sahil Malik Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync ----------------------------------------------------------------------------
32
3025
by: lcdgoncalves | last post by:
Hi everyone Is there a real need to use keyword static with functions, if we simply don't declare their prototypes in .h file? Many textbooks avoid to discuss this matter and/or discuss only the usage of static functions. I've been programming for years and I never felt a real need for the "static approach for functions". I don't know...
1
1574
by: wizwx | last post by:
I just noticed an interesting implementation of Singleton from Bruce Eckel's "Thinking in C++" vol. 2, pp 620: class Singleton { static Singleton s; public: static Singleton& instance() { return s; } // .... };
2
3140
by: DaTurk | last post by:
Hi, I have an interesting issue, well, it's not really an issue, but I'd like to understand the mechanics of what's going on. I have a file, in CLI, which has a class declared, and a static fuction. Because the class is declared globally, I declare it as static. Is a function with a namespace scope declared as static by default? So,...
0
7710
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8040
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8225
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8092
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1051
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.