PHP Classes

File: abstract.constants.class.php

Recommend this page to a friend!
  Classes of Steven Hoyt   Encapsulate PHP Constants in Class   abstract.constants.class.php  
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
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: 4 years ago
Size: 1,858 bytes

You need to be a registered user and login to get this file.

Login Immediately with your account on: