Index: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php |
— | — | @@ -283,7 +283,10 @@ |
284 | 284 | global $sfgFieldNum, $wgOut; |
285 | 285 | |
286 | 286 | // create an input of the called class |
287 | | - $calledClass = get_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()); |
288 | 291 | $input = new $calledClass ( $sfgFieldNum, $cur_value, $input_name, $is_disabled, $other_args ); |
289 | 292 | |
290 | 293 | // create calls to JS initialization and validation |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -819,4 +819,60 @@ |
820 | 820 | return $hasFactory ? SpecialPageFactory::getPage( $pageName ) : SpecialPage::getPage( $pageName ); |
821 | 821 | } |
822 | 822 | |
823 | | -} |
| 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 |