PHP Constant Web Development class -5 ( Define function, const keyword, Magic constants)

Опубликовано: 13 Март 2026
на канале: Axixa Technologies
212
13

PHP Constant
A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.
The name of a constant follows the same rules as any label in PHP. A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
No $ sign before the constant name.
Like superglobals, the scope of a constant is global.

Differences between constants and variables

There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.
Constants cannot be defined by simple assignment, they may only be defined using the define() function.
Constants may be defined and accessed anywhere without regard to variable scoping rules.
Once the Constants have been set, may not be redefined or undefined.

Syntax

There is two way to defining constant:
Define function
Const keyword

Define Function

Syntex:
define(NAME,value,case-insensitive)
Parameters:
NAME: Specifies the name of the constant
value: Specifies the value of the constant
case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false.

constant() this function will return the value of the constant.

Create a constant with a case-sensitive name:


2) Const Keyword

Syntex:

const NAME= value;
name: Specifies the name of the constant
value: Specifies the value of the constant.

Const keyword works both INSIDE and OUTSIDE of a class definition where define function only works OUTSIDE of a class definition.

Magic constants
Magic constants are the predefined constants in PHP which is used on the basis of their use. These constants are created by various extensions.
There are some magic constant in the PHP and all of the constant resolved at the compile-time, not like the regular constant which is resolved at run time. There are eight magic constants that start and end with double underscores (__).
PHP supports ten primitive types in Three group.
a) Four scalar(It holds only single value) types :
1. Boolean 2. Integer
3. Float (floating-point number, aka double)
4. String
b) Four compound(Multiple values in single variable) types:
5. Array
6. Object
7. Callable
8. Iterable
c) Two special types:
9. Resource
10. NULL

a.1) Boolean
This is the simplest type. Like a
switch that has only two states
ON means true(1) and OFF
means false(0)
A boolean expresses a truth
value. It can be either TRUE or
FALSE.
a.2) Integer
Integer means numeric data types.
Integer may be less than greater than
or equal to zero.
The size of an integer is
platform-dependent.
Integers hold only whole numbers
including positive and negative
numbers, i.e., numbers without
fractional part or decimal point. They
can be decimal (base 10) default, octal
(base 8) or hexadecimal (base 16) or
binary (base 2). The binary integers
can be declared with leading 0b and
the octal integers can be declared with
leading 0 and the hexadecimal can be
declared with leading 0x.
As of PHP 7.4.0, integer literals may
contain underscores (_) between
digits, for better readability of literals.


Download Notes Link:
https://axixatechnologies.com/youtube...
.............................................................................
The people of bikaner is also know about quality of Axixa technologies and Rajesh sir. Axixa is old and popular place for programming languages since 10 years.. we'll try to cover all basic and advanced topic of php in our php tutorials.


learn php with AXIXA technologies and have a nice day

If you want me to cover any topic related it sector you can comment down the topic we will try to cover that.

Rajesh purohit (+919251435299)
Email: [email protected]
Website: https://axixatechnologies.com/
Facebook:   / axixatechnology  

#Define #function #Const #keyword #Magic #constants #Scalar #Compound #Special #datatype #integer #AXIXA #Heredoc #nowdoc #Scope #syntax #php #web_development #free_classes #covid_19_special #stay_tuned #keep_watching #keep_supporting #subscribe_now #press_bell_icon #like #share #web_design #website_design