- 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
}
Questions and answers
What is the value?
- a) 2
- b) Warning: A already defined
How do you define a class constant?
- a) constant B = 1;
- b) const B = 1;
How do you call a class constant named CCC?
- a) $this->CCC
- b) self::CCC