- BASICS
- Quotes
-
Constants
- Control Structures
- Reference
- Number Systems
- VARIABLES
- Definition
- Variable Variable
- Exists
- Type Casting
- OPERATORS
- Aritmetic
- Bitwise
- String
- Comparison
- Logical
- FUNCTION
- Definition
- Anonymous
- Reference
- Variable Arguments
- ARRAY
- Basics
- Operations
- Create
- Search
- Modify
- Sort
- Storage
- STRING
- String Basics
- String Compare
- String Search
- String Replace
- String Format
- String Regexp
- String Parse
- Formating
- Json
- STREAMS
- File Open
- Read File
- Read Csv
- File Contents
- Context
- Ob_start
- OOP
- Object Instantiation
- Class Constructor
- Interfaces, Abstract
- Resource Visibility
- Class Constants
- Namespaces
- HTTP
- Headers
- File Uploads
- Cookies
- Sessions
Constants
A constant can't be changed once set.
/**
* Constants can be defined using the const keyword ...
* or by using the define()
*
* Can't be changed once set.
* Can be accessed for any scope within a script.
*/
error_reporting(E_ALL);
define('A', '1');
// const A = 1; // Warning: Constant A already defined
const B = 2;
const C = array(3);
{
echo A; # 1
echo B; # 2
echo C[0]; # 3
}
Class
The default visibility of class constants is public.
/**
* Class constants are allocated once per class, ...
* and not for each class instance.
*/
class MyClass {
const A = 1;
private const B = 2;
public function __construct() {}
}
echo MyClass::A; // 1
Last update: 531 days ago