Skip to content
Advertisement

Tag: constants

Is there a fancy and short solution for using the null coalescing operator with constants in PHP?

Since PHP 8 the constant() function throws an error instead of returning null and generating an E_WARNING when the given constant is not defined, and therefore I can’t use the following code to set a variable anymore: My obvious quick solution for this is changing that line to: It honestly bothers me a little because I like how the first

How to get class from a constant array?

I have about twenty different classes that are segregated in an assoc array similar to this: But now I want to do the array constant. I can make it using const VAL = array(); just fine. The problem lies in making new objects using those classes fails with Parse error: syntax error, unexpected ‘[‘, expecting ‘)’ error. I figured that

How to ensure, that column names are equal in laravel?

I am currently working on a laravel php project. In this case, a table containing countries should be created. There are three fields within the table: a short country code column called country_code and the name of the country in german and english language in the columns country_name_de and country_code_en. This results in the following model class: Further, there is

php-ffi: Return type const char* is a string

Why is the result of const char * a string and char * an object „byte-array“? A simple example: returns Removing const from the definition returns: Background A function of a dynamically linked external C library returns binary data which include NULL-bytes. When const is in the definition of the header file the resulting string is not complete = shortened

Alternative for define array php

I’m looking for an alternative for define(‘name’, array) as using an array in define gives me this error: Constants may only evaluate to scalar values in … The array I’m mentioning contains strings only. Answer From php.net… The value of the constant; only scalar and null values are allowed. Scalar values are integer, float, string or boolean values. It is

Advertisement