2011-06-20, 19:52:03
mvlcek Wrote:I guess this would be better performance wise, I just don’t like returns inside loops. Maybe put a break there instead.Zegnåt Wrote:I just meant a return directly after the eval.mvlcek Wrote:BTW: a return after the eval would be beneficialWhat kind of return would you suggest?
mvlcek Wrote:But as you mention it, in the I18N plugin I return, if the component exists or notI have one issues with your code as it stands: it doesn’t return whether the component actually works or not. eval() is no magic and the PHP inside might fail. My proposed return is this: (Where $eval holds the return value of eval().)
Code:
$eval===NULL||$eval!==FALSE;
Let me know what you think of that.
Combining:
Code:
function get_component($id) {
global $components;
if (func_num_args() > 1) { $args = func_get_args(); array_shift($args); }
if (!$components) {
if (file_exists(GSDATAOTHERPATH.'components.xml')) {
$data = getXML(GSDATAOTHERPATH.'components.xml');
$components = $data->item;
} else {
$components = array();
}
}
if (count($components) > 0) {
foreach ($components as $component) {
if ($id == $component->slug) {
$eval = eval("?>" . strip_decode($component->value) . "<?php ");
break;
}
}
}
return $eval===NULL||$eval!==FALSE;
}
If you can agree with this as a solution I could put it in the core right now.
“Don’t forget the important ˚ (not °) on the a,†says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!