Questions tagged [class-constants]

In object-oriented programming, a class constant is a constant defined within a class.

In object-oriented programming, a class constant is a defined within a .

97 questions
2
votes
1 answer

Fatal Error in PHP with PDO::MYSQL_ATTR_MAX_BUFFER_SIZE

With a PHP web application, I'm encountering a fatal error with PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, but only on very rare hosting plans. It's saying this constant is not available. How do I detect that it's not available and not use it? I mean, I can…
Volomike
  • 23,743
  • 21
  • 113
  • 209
1
vote
1 answer

PHP Class Constants Array Cast

To simulate enums in PHP I like to use class constants. e.g. class FRUIT { const apple = 1; const orange = 2; const lemon = 3; const pear = 4; }; I have a case where I'd like cast this class to an array to populate a select list.…
benedict_w
  • 3,543
  • 1
  • 32
  • 49
1
vote
3 answers

PHP Static class has a very long name - can I use a shorter pointer?

I have a static class with a very long name, example: class SomeClassWithAVeryLongName { const CONST_ONE = 'foo'; const CONST_TWO = 'bar'; } In my other class, I want to reference these constants. The problem is there are a bunch of them…
Maverick
  • 3,039
  • 6
  • 26
  • 35
1
vote
1 answer

Definition of class constants in cpp class declaration

Although in principle it seems that only integral values can be declared as class constants in the declaration of a class: struct Foo{ static const int N=10; }; In my code, looking for alternatives that would not force me to define a float…
1
vote
1 answer

How can I reference my constant within a Jenkins Parameter?

I have the following code in a Pipelineconstant.groovy file: public static final list ACTION_CHOICES = [ N_A, FULL_BLUE_GREEN, STAGE, FLIP, CLEANUP ] and this PARAMETERS in Jenkins multi-Rapper-file: parameters { string…
1
vote
2 answers

Constants in PHP5

I have a class in which I want to define some constants used by other classes. The const keyword isn't enough for me because I want for example to use a mathematical expression like 2.0 * pi() as a constant. How is done?
Razvan
  • 319
  • 3
  • 11
1
vote
3 answers

PHP: Class constants in type declarations of input paramaters

For a custom logger I want to force the caller to pass a valid class constant defined in Psr\Log\LogLevel. This class is defined like: namespace Psr\Log; /** * Describes log levels. */ class LogLevel { const EMERGENCY = 'emergency'; const…
Blackbam
  • 17,496
  • 26
  • 97
  • 150
1
vote
0 answers

PHP: Add constants to a class on runtime

i have the following code: interface ITest { const SIGNAL_FOO = 'foo'; } class SomeClass extends SignalSlotObject implements ITest { const SIGNAL_BAR = 'bar'; } SignalSlotObject fetches all constants beginning with 'SIGNAL_' at runtime from…
Florian
  • 3,145
  • 1
  • 27
  • 38
1
vote
0 answers

Reduce class constraints in haskell and inspecting persistent tables

I'm trying to setup a basic endpoint which takes an id and goes through a join table to return all joined records using persistent and spock, a working implementation looks like this. get ("songs" var) $ \id -> do song <- getRecord404 $…
SJH
  • 43
  • 1
  • 3
1
vote
1 answer

Accessing Codeigniter model constants from outside the model

I am working on a Codeigniter project and would like to start using constants. I know that Codeigniter supports global constants and also I've managed to implement it in a scope of a model. In the beginning of the "Baz" model: const FOO =…
David Šili
  • 117
  • 2
  • 12
1
vote
1 answer

This static class field is being used before it's been created?

So, I've been experimenting with static class fields (especially the constant ones), and got myself into.... this: #include #include class Test { public: Test() { std::cout << "Constructing (Default CTOR)\n"; } Test(int…
Michael
  • 548
  • 6
  • 23
1
vote
2 answers

PHP Class variables with Constants

I am getting a parse error on the lines with the constant (DEPLOYMENT). Why is this now allowed, or am I missing something. Parse error: parse error, expecting `')'' in class UploadComponent extends Object { private $config = array( …
Lizard
  • 43,732
  • 39
  • 106
  • 167
1
vote
1 answer

Difference between literal string and constants

I am about to replace all the literal string in the message with the constants. But really wanted to know is there any performance optimization behind this or is just for following coding standards. In below sample I have class Constants. What are…
Rajaram Shelar
  • 7,537
  • 24
  • 66
  • 107
1
vote
4 answers

[PHP]: Use function return as array data in static class definition

I'm having problems with this class definition because of the definition of $directories. Please help: realpath(__DIR__), "root" =>…
Fortisimo
  • 1,012
  • 2
  • 11
  • 26
1
vote
1 answer

How to use defined() method with 'Class Constants' that are defined into a specific class in PHP?

Following is the small code snippet of a class code:
PHPLover
  • 1
  • 51
  • 158
  • 311