Hi,
I’d like to have something like - class MyClass
-
{
-
const HASH = array(…);
-
}
but that’s not allowed, so my question is, should I use a standard or static property instead? - class MyClass
-
{
-
private static $HASH = array(…);
-
// or
-
private $HASH = array(…);
-
}
8 4063
I don't know of any other options than to use either a standard or static property
and which would you prefer, and why?
Perhaps if you describe your requirement we could offer some advice :)
ok (though it won’t make much difference)
initially I wanted a constant (= unchangeable) array in the class, to use it in one of the methods. const HASH = array(…); would have been perfect for that purpose, but it’s not allowed, leaving me with the choice of either using protected $HASH = array(…); or protected static $HASH = array(…);. now I’d like to know, which one would be better.
serialize your array and put it in a constant :)
Yes that means you can still change it when you unserialize() it. :)
These are the odd cases where PHP does not come up to par with C++.
Use static just so you know you should behave differently while using it, and hopefully to remember to not change it.
Explain your situation a little bit more and I might suggest something else.
Dan
serialize your array and put it in a constant :)
very funny, indeed.
I never though such a simple question can get so complicated.
The way you have it is how I'd do it.
If I was hell-bent on making sure it did not change, I'd make a singleton class and make all the error-codes in there constants and its 2 methods static.
So then I'd use it like this for your deny() function: -
-
if(HTTP_Headers::isValid($code))
-
-
header("HTTP/1.1 $code " . HTTP_Headers::get([$code]));
-
-
Dan, [the php nut @]
firstly, Abstract Registry is better than Singleton.
secondly, too much computing for that simple purpose.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kyle |
last post by:
Hi,
Is it possible to initialize a constant memeber array in a class?
I tried several syntax but all failed.
class A
{
public:
A();
~A();
private:
|
by: Rade |
last post by:
Please have a look at the following program:
#include <iostream>
template <const int array, size_t index>
class ArrayIndex
{
public:
static const int value = array;
};
|
by: Mark Dunmill |
last post by:
I can't create a Constant/Read-only array field in managed C++ classes -
doesn't allow the keyword const pointer to const object on array fields in
managed C++ classes. e.g. Want to define a...
|
by: danbraund |
last post by:
Hi everyone, I'm a long time C coder, who is coding his final year
project in C++ to run under the MIT click routing system. Being fairly
new to the OO side of the language, my problem is this:
...
|
by: howachen |
last post by:
which one is recommend?
seems they perform the same thing...
regards,
howa
|
by: jayharris |
last post by:
I'm having a ton of trouble initializing a multi-dimensional array
inside a constructor, largely because I don't know the size of the
array until runtime. I have a class that looks like this:
...
|
by: toton |
last post by:
Hi,
In C++ when I initialize an array it, also initializes the class that
it contains, which calls the default constructor. However, I want to
initialize the array only (i.e reserve the space) and...
|
by: barcaroller |
last post by:
Can variables be used for array size in C++? I know that in the past, I
could not do the following:
foo (int x)
{
type arr;
}
I have recently seen code that does exactly that. Is it right?
|
by: longbrmb |
last post by:
I'm new to C++/CLI and my main background is Java. I'm trying to
create an array of constants as a static member of a class. An
example is shown below:
public ref class TestClass {
public:...
|
by: Christof Warlich |
last post by:
Hi,
the subject says it all: I need to instantiate an array of objects
where each object "knows" its arrary index. So far, this is easy
as long as index is not a compile-time constant:
class ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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...
| |