note 84629 modified in keyword.paamayim-nekudotayim by danbrown
| From: | danbrown@php.net | Date: | Tue, 22 Jul 2008 18:13:40 +0000 |
| Subject: | note 84629 modified in keyword.paamayim-nekudotayim by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142514@lists.php.net to get a copy of this message | ||
Using PHP 4, I was unable to see an easy method for retrieving static constants in a library, as
well as static functions. There was no need to set variables, as the library is final, used for
Configuration settings.
<?php
class StaticLibrary
{
//static constants are set here
function finalConstants(&$Vars)
{
$Vars['someVar'] = 'Hello';
$Vars['anotherVar'] = 'World';
$Vars['moreVars'] = 'Keep It Coming';
}
//usage: StaticLibrary::vars('someVar')
function vars($v)
{
static $Vars;
if (!is_array($Vars)) { $Vars = array(); StaticLibrary::finalConstants($Vars); } //setup
access to the static contants in our Final library
return($Vars[$v]); //return some var
}
//usage: StaticLibrary::staticFunction('Some string and I want to ')
function staticFunction($str)
{
$str .= 'freak that string!';
return $str;
}
}
?>
I appreciate the ideas below!!
--was--
Using PHP 4, I was unable to see an easy method for retrieving static constants in a library, as
well as static functions. There was no need to set variables, as the library is final, used for
Configuration settings.
class StaticLibrary
{
//static constants are set here
function finalConstants(&$Vars)
{
$Vars['someVar'] = 'Hello';
$Vars['anotherVar'] = 'World';
$Vars['moreVars'] = 'Keep It Coming';
}
//usage: StaticLibrary::vars('someVar')
function vars($v)
{
static $Vars;
if (!is_array($Vars)) { $Vars = array(); StaticLibrary::finalConstants($Vars); } //setup
access to the static contants in our Final library
return($Vars[$v]); //return some var
}
//usage: StaticLibrary::staticFunction('Some string and I want to ')
function staticFunction($str)
{
$str .= 'freak that string!';
return $str;
}
}
I appreciate the ideas below!!
http://php.net/manual/en/keyword.paamayim-nekudotayim.php