r111567 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111566‎ | r111567 | r111568 >
Date:19:39, 15 February 2012
Author:jeroendedauw
Status:reverted
Tags:
Comment:
follow up to r111468 - put in compatibility for php 5.2 using debug_backtrace hack
Modified paths:
  • /trunk/phase3/includes/DBTable.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DBTable.php
@@ -540,13 +540,44 @@
541541 static $instance;
542542
543543 if ( !isset( $instance ) ) {
544 - $instance = new static;
 544+ $class = function_exists( 'get_called_class' ) ? get_called_class() : self::get_called_class();
 545+ $instance = new $class;
545546 }
546547
547548 return $instance;
548549 }
549550
550551 /**
 552+ * Compatibility fallback function so the singleton method works on PHP < 5.3.
 553+ * Code borrowed from http://www.php.net/manual/en/function.get-called-class.php#107445
 554+ *
 555+ * @since 1.20
 556+ *
 557+ * @return string
 558+ */
 559+ protected static function get_called_class() {
 560+ $bt = debug_backtrace();
 561+ $l = count($bt) - 1;
 562+ $matches = array();
 563+ while(empty($matches) && $l > -1){
 564+ $lines = file($bt[$l]['file']);
 565+ $callerLine = $lines[$bt[$l]['line']-1];
 566+ preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l--]['function'].'/',
 567+ $callerLine,
 568+ $matches);
 569+ }
 570+ if (!isset($matches[1])) $matches[1]=NULL; //for notices
 571+ if ($matches[1] == 'self') {
 572+ $line = $bt[$l]['line']-1;
 573+ while ($line > 0 && strpos($lines[$line], 'class') === false) {
 574+ $line--;
 575+ }
 576+ preg_match('/class[\s]+(.+?)[\s]+/si', $lines[$line], $matches);
 577+ }
 578+ return $matches[1];
 579+ }
 580+
 581+ /**
551582 * Get an array with fields from a database result,
552583 * that can be fed directly to the constructor or
553584 * to setFields.

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111468follow up to r111264; split up class into one representing a table and one re...jeroendedauw18:11, 14 February 2012

Status & tagging log