Markus, Fabian, and gentlemen:
In building the SMW_DV_Time.php function, I noticed that you declared
certain arrays as protected, because string constants and array
constants are not supported.
This is correct as far as it goes. But when you have a string variable
or array whose contents are initialized with the class and never change,
you shouldn't need to re-initialize them every time you create an
object. And you don't.
Instead of declaring them to be merely "protected" or even "private,"
why not also declare them /static/?
That I have done, and tested them with good results.
The enclosed patch changes all protected but unchanging arrays to
/private static/ arrays, and changes their identifiers from $this->m_x
to self::$m_x wherever they appear.
Temlakos
--- ../SemanticMediaWiki-lng/SMW_DV_Time.php 2009-08-12 08:24:10.000000000
-0400
+++ ./SMW_DV_Time.php 2009-08-12 10:09:45.000000000 -0400
@@ -95,13 +95,13 @@
protected $m_dayj = false; // Julian day, remains false if unspecified
protected $m_monthj = false; // Julian month, remains false if
unspecified
protected $m_yearj = false; // Julian year, remains false if unspecified
- // The following are constant (array-valued constants are not
supported, hence the decalration as variable):
- protected $m_months = array("January", "February", "March", "April" ,
"May" , "June" , "July" , "August" , "September" , "October" , "November" ,
"December");
- protected $m_monthsshort = array("Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
- protected $m_formats = array( SMW_Y => array('year'), SMW_YM =>
array('year','month'), SMW_MY => array('month','year'), SMW_YDM =>
array('year','day','month'), SMW_YMD => array('year','month','day'), SMW_DMY =>
array('day','month','year'), SMW_MDY => array('month','day','year'));
- protected $m_daysofmonths = array ( 1 => 31, 2 => 29, 3 => 31, 4 => 30,
5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31 );
+ // The following are constant (array-valued constants are not
supported, hence the declaration as private static variable):
+ private static $m_months = array("January", "February", "March",
"April" , "May" , "June" , "July" , "August" , "September" , "October" ,
"November" , "December");
+ private static $m_monthsshort = array("Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
+ private static $m_formats = array( SMW_Y => array('year'), SMW_YM =>
array('year','month'), SMW_MY => array('month','year'), SMW_YDM =>
array('year','day','month'), SMW_YMD => array('year','month','day'), SMW_DMY =>
array('day','month','year'), SMW_MDY => array('month','day','year'));
+ private static $m_daysofmonths = array ( 1 => 31, 2 => 29, 3 => 31, 4
=> 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 =>
31 );
// Time zone monikers and their associated offsets in hours and
fractions of hours
- protected $m_tz = array("A" => 1, "ACDT" => 10.5, "ACST" => 9.5, "ADT"
=> -3, "AEDT" => 11,
+ private static $m_tz = array("A" => 1, "ACDT" => 10.5, "ACST" => 9.5,
"ADT" => -3, "AEDT" => 11,
"AEST" => 10, "AKDT" => -8, "AKST" => -9, "AST" => -4, "AWDT"
=> 9, "AWST" => 8,
"B" => 2, "BST" => 1, "C" => 3, "CDT" => -5, "CEDT" => 2,
"CEST" => 2,
"CET" => 1, "CST" => -6, "CXT" => 7, "D" => 4, "E" => 5, "EDT"
=> -4,
@@ -163,7 +163,7 @@
"GMT|H(A[DS]T|[AN][ACEPRTY])|IST|M(DT|E(S)?Z|S[DKT])|N[DFS]T|P[DS]T|UTC/u";
if(preg_match($regexptz, $filteredvalue, $match)) {
// Retrieve the offset and store it as the initial time
offset value.
- $this->m_timeoffset = $this->m_timeoffset +
$this->m_tz[$match[0]]/24;
+ $this->m_timeoffset = $this->m_timeoffset +
self::$m_tz[$match[0]]/24;
$regexp = "/(\040|T){0,1}".str_replace("+", "\+",
$match[0])."(\040){0,1}/u"; //delete tz moniker and preceding and following
chars
$filteredvalue = preg_replace($regexp,'',
$filteredvalue); //value without the tz moniker
}
@@ -204,7 +204,7 @@
$time = $match[0];
//timezone handling (Zulu, Romeo, Sierra, etc.)
if(preg_match("/[A-IK-Z]/u",$time, $match2)){//get
military timezone offset
- $this->m_timeoffset = $this->m_timeoffset +
$this->m_tz[$match2[0]]/24;
+ $this->m_timeoffset = $this->m_timeoffset +
self::$m_tz[$match2[0]]/24;
$time =
str_replace($match2[0],'',$time);//strip away the one-letter moniker
}
$hours = substr($time,0,2);
@@ -247,7 +247,7 @@
foreach ($dateformats[$digitcount] as $format) { //check
whether created band matches dateformats
if (!(~$band & $format)) { //check if $format => $band
("the detected band supports the current format")
$i = 0;
- foreach ($this->m_formats[$format] as
$globalvar) { // map format digits to internal variables
+ foreach (self::$m_formats[$format] as
$globalvar) { // map format digits to internal variables
$globalvar = 'm_'.$globalvar; // (for
searching this file) this is one of: m_year, m_month, m_day
if($prelimModel == 'Jl') {
$globalvar = $globalvar . 'j';
@@ -265,11 +265,11 @@
wfLoadExtensionMessages('SemanticMediaWiki');
$this->addError(wfMsgForContent('smw_nodatetime',$value));
return true;
- } elseif ( ($this->m_day > 0) && ($this->m_day >
$this->m_daysofmonths[$this->m_month]) ) { //date does not exist in Gregorian
calendar
+ } elseif ( ($this->m_day > 0) && ($this->m_day >
self::$m_daysofmonths[$this->m_month]) ) { //date does not exist in Gregorian
calendar
wfLoadExtensionMessages('SemanticMediaWiki');
$this->addError(wfMsgForContent('smw_nodatetime',$value));
return true;
- } elseif ( ($this->m_dayj > 0) && ($this->m_dayj >
$this->m_daysofmonths[$this->m_monthj]) ) { //date does not exist in Julian
calendar
+ } elseif ( ($this->m_dayj > 0) && ($this->m_dayj >
self::$m_daysofmonths[$this->m_monthj]) ) { //date does not exist in Julian
calendar
wfLoadExtensionMessages('SemanticMediaWiki');
$this->addError(wfMsgForContent('smw_nodatetime',$value));
return true;
@@ -316,11 +316,11 @@
if ( $retVal !== false ) {
return $retVal;
}
- $retVal = array_search($label, $this->m_months);
+ $retVal = array_search($label, self::$m_months);
if ( $retVal !== false ) {
return $retVal + 1;
}
- $retVal = array_search($label, $this->m_monthsshort);
+ $retVal = array_search($label, self::$m_monthsshort);
if ( $retVal !== false ) {
return $retVal + 1;
}
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel