Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php constant can be referenced but defined() returns false

Tags:

php

constants

Has anyone encountered this?

var_dump(CRYPT_SHA256 == 1); // returns bool(true)
var_dump(defined(CRYPT_SHA256)); // returns bool(false)
like image 202
Dave B Avatar asked Dec 12 '12 15:12

Dave B


People also ask

Can you define a constant in PHP?

A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name).

What is define () in PHP?

define() function in PHP The define() function defines a constant.

Which of the following is correct about constants in PHP?

Q 3 - Which of the following is correct about constants vs variables in PHP? A - Constants may be defined and accessed anywhere without regard to variable scoping rules.

What is the purpose of constant () function in PHP?

constant() is useful if you need to retrieve the value of a constant, but do not know its name. I.e. it is stored in a variable or returned by a function. This function works also with class constants.


1 Answers

defined('CRYPT_SHA256')

Otherwise, you are asking whether the value of the CRYPT_SHA256 constant is also the name of another constant....

defined(CRYPT_SHA256) === defined('1');
like image 169
Wrikken Avatar answered Sep 20 '22 23:09

Wrikken