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
0
votes
1 answer

Class constant not accepted by php 5.4

I have a class constant const DATE_REGEX = '@^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$@'; which I want to use in a static array as part of a string: public static $rules = [ 'startdate' => ['required','regex:' .…
Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
0
votes
2 answers

php get the value of a constant

I want to get the value of a constant "test" using "test1". I have tried it but only getting "test1" value but not "test" value.
Pavan
  • 13
  • 5
0
votes
1 answer

Swift init infinite loop with default constant value

I have UIViewController subclass. I have a constant that I wanted to lazy load. To do this I used a function to set it's default value. I have the two init methods in here because I was previously using them to set the value. Then I found that I…
Brian
  • 3,571
  • 7
  • 44
  • 70
0
votes
3 answers

Class constant final variable

This is my code. I need wordOfTheDay and answer to stay the same. I need a user to input an answer for "What is the word of the day" and "What is the answer to 3*8" and depending on their answer it will either be accepted as the correct answer or…
user4055424
0
votes
0 answers

Defining many constants

I have to declare about 300 constants and was wondering if there is any faster, better way than to write each one out individually. const CHANNEL1 = "G"; const CHANNEL2 = "U"; const CHANNEL3 = "E"; …
Dave Gray
  • 1
  • 1
0
votes
1 answer

Access constant of a class member object doesn't work

if I try the following example (PHP 5.4) I get the following error: Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';' class a { public $p; public function __construct() { $this->p = new b; …
the_tiger
  • 346
  • 1
  • 9
0
votes
1 answer

Access a const?

Here's my var, it's a const: const TWITTER_CACHE_REFRESH = 1440; How can I access it in a method in the same class that I declare it? The class it's in has already been initialized by another class.
panthro
  • 22,779
  • 66
  • 183
  • 324
0
votes
0 answers

Get Ancestor Class Name that Defines CONST in PHP?

I have a class hierarchy in PHP and in some of the parent classes I have defined a constant, let's assume that constant is called TYPE for my example. I want to be able to pass in a valid value for TYPE that one of my classes may have defined and…
MikeSchinkel
  • 4,947
  • 4
  • 38
  • 46
0
votes
2 answers

Test classes with common behavior

I have to write some integration test classes in the Hybris Commerce Suite and most of them share a common behavior to set up the system (Site, Store, Catalog, Country, ...) or to perform some common action like create a customer. I created an…
Vincenzo
  • 130
  • 1
  • 3
  • 12
0
votes
0 answers

Zend framework Undefined class constant '' in Zend/Db/Select.php

There is a srange error in my Apache Log : PHP Fatal error: Undefined class constant '' This is on line 814 of de library (Zend framework 1.11) library/Zend/Db/Select.php A look of the code : if ($type == self::FROM) { // append this from…
0
votes
1 answer

How do I access constants from a external required file in PHP?

I have this class i making that works if I keep the constants in the class code, but i wanted to access them from an external file that the user can comment or uncomment out c constant value. it works great this way but I do not want the users…
0
votes
1 answer

php concatenating string to classconstant in array assignment

following doesn't work: self::t . 'hello'); } var_dump(test::$y); ?> can somebody tell me why that is? :) it fails in the ... => self::t . 'hello')... part, where it, as seams,…
Mads Buch
  • 344
  • 2
  • 10
-1
votes
2 answers

How to initialize private static constant array of the same class C++

I need to make class B to work with graph of related objects of class A. An instance of B contains A by value, and links to linked B objects(array indexes). Array of B must to be private as OOP principles dictate. I have long generated…
-1
votes
1 answer

FieldInfo.GetRawConstantValue is not avaliable on UWP

I need to get a value of a constant inside my class. GetField works fine. But then myFieldInfo.GetRawConstantValue() normally works perfectly, but is not available on UWP. Is there any way to achieve this on UWP?
Do-do-new
  • 794
  • 8
  • 15
-1
votes
3 answers

Why the class constant value is getting evaluated in one statement and not in other?

I'm using PHP 7.2.6 I've tried following program :
PHPLover
  • 1
  • 51
  • 158
  • 311