PLZ: A handy PHP library for lazy programmers
  • Namespace
  • Class
  • Tree
  • Todo

Namespaces

  • amekusa
    • plz
  • PHP

Classes

  • alt
  • arr
  • constant
  • dom
  • fn
  • num
  • obj
  • op
  • path
  • str
  • sys
  • T
  • type
  • xml

Exceptions

  • ErrorException

Class constant

Constant utilities

To get started, place the following line around top of your code.

use amekusa\plz\constant;
Abstract
Namespace: amekusa\plz
Located at constant.php

Methods summary

public static mixed
# get( string $X, mixed $Alt = null, boolean $Defines = false )

Returns the value of constant:$X

Returns the value of constant:$X

If the constant is undefined, returns the 2nd argument. Additionally, if the 3rd is true, defines constant:$X of which value is the 2nd.

Parameters

$X
The name of a constant
$Alt
(optional) The alternative value to return if constant:$X is undefined
$Defines
(optional) Whether or not to define constant:$X if it is undefined

Returns

mixed
The value of constant:$X or $Alt

Example

Demonstration

define('CONST_X', 'I am CONST_X.');
define('CONST_Y', 'I am CONST_Y.');
var_dump( constant::get('CONST_X')                      );
var_dump( constant::get('CONST_Y')                      );
var_dump( constant::get('CONST_Z')                      ); // Alternates with NULL
var_dump( constant::get('CONST_Z', 'No such constant!') ); // Alternates with a string
string(13) "I am CONST_X."
string(13) "I am CONST_Y."
NULL
string(17) "No such constant!"

Just-in-Time define()

define('CONST_X', 'I am CONST_X.');
define('CONST_Y', 'I am CONST_Y.');
var_dump( constant::get('CONST_X')                        );
var_dump( constant::get('CONST_Y')                        );
var_dump( constant::get('CONST_Z', 'I am CONST_Z.', true) );
echo 'Hi, ' . CONST_X . "\n";
echo 'Hi, ' . CONST_Y . "\n";
echo 'Hi, ' . CONST_Z . "\n";
string(13) "I am CONST_X."
string(13) "I am CONST_Y."
string(13) "I am CONST_Z."
Hi, I am CONST_X.
Hi, I am CONST_Y.
Hi, I am CONST_Z.

PLZ: A handy PHP library for lazy programmers API documentation generated by ApiGen