mirror of
https://github.com/moodle/moodle.git
synced 2025-06-03 22:55:39 +02:00
Faster block_method_result(), my back-of-the-envelope benchmarks say that
call_user_func is about 3 times faster than eval(). Which is no surpise. ;-) Faster block_load_class() by checking if the block class is already present instead of relying on require_once() and include_once() which have include paths and other nasties to take into account.
This commit is contained in:
parent
bd8be2bb38
commit
a9033ad5f8
@ -83,13 +83,11 @@ function get_class_constructor($classname) {
|
||||
}
|
||||
|
||||
//This function retrieves a method-defined property of a class WITHOUT instantiating an object
|
||||
//It seems that the only way to use the :: operator with variable class names is eval() :(
|
||||
//For caveats with this technique, see the PHP docs on operator ::
|
||||
function block_method_result($blockname, $method) {
|
||||
if(!block_load_class($blockname)) {
|
||||
return NULL;
|
||||
}
|
||||
return eval('return block_'.$blockname.'::'.$method.'();');
|
||||
return call_user_func(array('block_'.$blockname, $method));
|
||||
}
|
||||
|
||||
//This function creates a new object of the specified block class
|
||||
@ -110,15 +108,19 @@ function block_instance($blockname, $instance = NULL) {
|
||||
function block_load_class($blockname) {
|
||||
global $CFG;
|
||||
|
||||
if (empty($blockname)) {
|
||||
if(empty($blockname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
|
||||
$classname = 'block_'.$blockname;
|
||||
|
||||
if(class_exists($classname)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
|
||||
include_once($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php');
|
||||
|
||||
// After all this, return value indicating success or failure
|
||||
return class_exists($classname);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user