r30144 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r30143 | r30144 (on ViewVC) | r30145 >
Date:07:43, 25 January 2008
Author:tstarling
Status:ok
Tags:
Comment:Workaround for segfault observed on parse for certain input text. Related to PHP bug 35229, but was observed in call_user_func_array() not call_user_func(). Apparently autoloading is buggy especially when invoked from an unusual context. My workaround is to trigger early autoloading using is_callable(). And if we're going to call is_callable(), we may as well do something sensible if it returns false, right?
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Parser.php
===================================================================
--- trunk/phase3/includes/Parser.php	(revision 30143)
+++ trunk/phase3/includes/Parser.php	(revision 30144)
@@ -2835,6 +2835,10 @@
 						$allArgs = array_merge( $initialArgs, $funcArgs );
 					}
 
+					# Workaround for PHP bug 35229 and similar
+					if ( !is_callable( $callback ) ) {
+						throw new MWException( "Tag hook for $name is not callable\n" );
+					}
 					$result = call_user_func_array( $callback, $allArgs );
 					$found = true;
 
@@ -3239,6 +3243,10 @@
 					break;
 				default:
 					if( isset( $this->mTagHooks[$name] ) ) {
+						# Workaround for PHP bug 35229 and similar
+						if ( !is_callable( $this->mTagHooks[$name] ) ) {
+							throw new MWException( "Tag hook for $name is not callable\n" );
+						}
 						$output = call_user_func_array( $this->mTagHooks[$name],
 							array( $content, $attributes, $this ) );
 					} else {
Views
Toolbox