r109841 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109840‎ | r109841 | r109842 >
Date:18:54, 23 January 2012
Author:foxtrott
Status:ok
Tags:
Comment:
fix bug 33832 ([SF] undefined function get_called_class() SF_FormInput.php on line 286)
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php
@@ -283,10 +283,15 @@
284284 global $sfgFieldNum, $wgOut;
285285
286286 // create an input of the called class
287 - // TODO: get_called_class was introduced in PHP 5.3. The call to
288 - // SF_Utils::get_called_class() can be removed once support for PHP 5.2
289 - // is dropped.
290 - $calledClass = function_exists('get_called_class')?(get_called_class()):(SF_Utils::get_called_class());
 287+ // TODO: get_called_class was introduced in PHP 5.3. The use of the
 288+ // backtrace should be removed once support for PHP 5.2 is dropped.
 289+ if ( function_exists('get_called_class') ) {
 290+ $calledClass = get_called_class();
 291+ } else {
 292+ $bt = debug_backtrace();
 293+ $calledClass = $bt[1]['args'][0][0];
 294+ }
 295+
291296 $input = new $calledClass ( $sfgFieldNum, $cur_value, $input_name, $is_disabled, $other_args );
292297
293298 // create calls to JS initialization and validation
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -819,60 +819,4 @@
820820 return $hasFactory ? SpecialPageFactory::getPage( $pageName ) : SpecialPage::getPage( $pageName );
821821 }
822822
823 - /**
824 - * Compatibility function.
825 - *
826 - * This delivers the PHP 5.3 functionality also for 5.2
827 - * Pretty ugly.
828 - *
829 - * Taken from http://djomla.blog.com/2011/02/16/php-versions-5-2-and-5-3-get_called_class/
830 - *
831 - * @param type $backtrace
832 - * @param type $level
833 - * @return type
834 - */
835 - function get_called_class( $backtrace = false, $level = 1 ) {
836 - if ( !$backtrace )
837 - $backtrace = debug_backtrace();
838 - if ( !isset( $backtrace[$level] ) )
839 - throw new Exception( "Cannot find called class -> stack level too deep." );
840 - if ( !isset( $backtrace[$level]['type'] ) ) {
841 - throw new Exception( 'type not set' );
842 - }
843 - else
844 - switch ( $backtrace[$level]['type'] ) {
845 - case '::':
846 - $lines = file( $backtrace[$level]['file'] );
847 - $i = 0;
848 - $callerLine = '';
849 - do {
850 - $i++;
851 - $callerLine = $lines[$backtrace[$level]['line'] - $i] . $callerLine;
852 - } while ( stripos( $callerLine, $backtrace[$level]['function'] ) === false );
853 - preg_match( '/([a-zA-Z0-9\_]+)::' . $backtrace[$level]['function'] . '/', $callerLine, $matches );
854 - if ( !isset( $matches[1] ) ) {
855 - // must be an edge case.
856 - throw new Exception( "Could not find caller class: originating method call is obscured." );
857 - }
858 - switch ( $matches[1] ) {
859 - case 'self':
860 - case 'parent':
861 - return get_called_class( $backtrace, $level + 1 );
862 - default:
863 - return $matches[1];
864 - }
865 - // won't get here.
866 - case '->': switch ( $backtrace[$level]['function'] ) {
867 - case '__get':
868 - // edge case -> get class of calling object
869 - if ( !is_object( $backtrace[$level]['object'] ) )
870 - throw new Exception( "Edge case fail. __get called on non object." );
871 - return get_class( $backtrace[$level]['object'] );
872 - default: return $backtrace[$level]['class'];
873 - }
874 -
875 - default: throw new Exception( "Unknown backtrace method type" );
876 - }
877 - }
878 -
879 -}
\ No newline at end of file
 823+}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109740fix bug 33832 ([SF] undefined function get_called_class() SF_FormInput.php on...foxtrott15:23, 22 January 2012

Status & tagging log