r79547 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79546‎ | r79547 | r79548 >
Date:01:51, 4 January 2011
Author:soxred93
Status:ok (Comments)
Tags:
Comment:
Forcing array breaks MWFunction with <2 parameters
Modified paths:
  • /trunk/phase3/includes/MWFunction.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/GlobalTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/GlobalTest.php
@@ -421,8 +421,8 @@
422422 array_unshift( $param_set, $sampleUTF );
423423
424424 $this->assertEquals(
425 - call_user_func_array( 'mb_substr', $param_set ),
426 - call_user_func_array( array( 'Fallback', 'mb_substr' ), $param_set ),
 425+ MWFunction::callArray( 'mb_substr', $param_set ),
 426+ MWFunction::callArray( 'Fallback::mb_substr', $param_set ),
427427 'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
428428 );
429429 }
@@ -451,14 +451,14 @@
452452 array_unshift( $param_set, $sampleUTF );
453453
454454 $this->assertEquals(
455 - call_user_func_array( 'mb_strpos', $param_set ),
456 - call_user_func_array( array( 'Fallback', 'mb_strpos' ), $param_set ),
 455+ MWFunction::callArray( 'mb_strpos', $param_set ),
 456+ MWFunction::callArray( 'Fallback::mb_strpos', $param_set ),
457457 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
458458 );
459459
460460 $this->assertEquals(
461 - call_user_func_array( 'mb_strrpos', $param_set ),
462 - call_user_func_array( array( 'Fallback', 'mb_strrpos' ), $param_set ),
 461+ MWFunction::callArray( 'mb_strrpos', $param_set ),
 462+ MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ),
463463 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
464464 );
465465 }
Index: trunk/phase3/includes/MWFunction.php
@@ -30,8 +30,6 @@
3131 }
3232 }
3333
34 - $callback = (array) $callback;
35 -
3634 if( count( $callback ) == 2 && $callback[0] == 'self' || $callback[0] == 'parent' ) {
3735
3836 throw new MWException( 'MWFunction cannot call self::method() or parent::method()' );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79523Throw an exception if calling parent or self on MWFunction.soxred9320:19, 3 January 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   22:32, 14 June 2011

"if( count( $callback ) == 2 && $callback[0] == 'self' || $callback[0] == 'parent' )"

But now $callback can be a string. PHP will return 1 (non-countable) in this case, but it's still a bit funky.

Status & tagging log