| File: | 
abstract.constants.class.php | 
 
| Role: | 
Class source | 
 
| Content type: | 
text/plain | 
 
| Description: | 
AbstractConstants | 
 
| Class: | 
Encapsulate PHP Constants in Class 
Encapsulate several constants in the same class | 
 
| Author: | 
By Steven Hoyt | 
 
|  Last change: | 
Added a __toString() magic function that will return a string reporting the called class' name, its constants and its properties. 
 
For example: 
 
<?php 
//////////////////////////////////////////////////////////// 
// required files 
require_once 'abstract.constants.class.php'; 
//////////////////////////////////////////////////////////// 
// class definitions 
class Application extends AbstractConstants 
{ 
  const VERSION         = '1.0' ; 
  public static $db             ; 
  public static $title          ; 
  public static function Initialize($title) 
  { 
    self::$db     = self::$db     ?: new PDO('sqlite:<path to db>/example.db'); 
    self::$title  = self::$title  ?: $title; 
  } 
} 
//////////////////////////////////////////////////////////// 
// testing magic __toString() function 
Application::Initialize('Testing ...'); 
echo '<pre style="font:11px courier new; text-align:left;">+' . Application::getInstance()  . "</pre>\r\n"; 
//////////////////////////////////////////////////////////// 
// expected output 
Array 
( 
    [__CLASS__] => Application 
    [VERSION] => 1.0 
    [db] => PDO Object 
    [title] => Testing ... 
) | 
 
| Date: | 
5 years ago | 
 
| Size: | 
1,858 bytes | 
 
 | 
 
 
 | 
 |