PROGRAMMING

  MINTE9
REMEMBERS




Last update:   20-02-2022

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');
define('A', '2'); // Warning: Constant CCC 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;
 
    public function  __construct() 
    {
    }
}

echo MyClass::A; // 1

Questions     github Basics
Control structures
        A B C D E F
🔔
1/3