Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
optional parameters of "component"
#16
mvlcek Wrote:
Zegnåt Wrote:
mvlcek Wrote:BTW: a return after the eval would be beneficial
What kind of return would you suggest?
I just meant a return directly after the eval.
I guess this would be better performance wise, I just don’t like returns inside loops. Maybe put a break there instead.

mvlcek Wrote:But as you mention it, in the I18N plugin I return, if the component exists or not
I 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;
Any eval() that just runs code will return NULL on success, it will return FALSE if it encounters a PHP error or it might return any arbitrary value if someone used “return”. The above code will return TRUE if the component has produced a non-FALSE response.

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!
Reply


Messages In This Thread
optional parameters of "component" - by bugman - 2011-06-08, 21:29:05
optional parameters of "component" - by bugman - 2011-06-08, 21:46:44
optional parameters of "component" - by mvlcek - 2011-06-08, 21:53:29
optional parameters of "component" - by bugman - 2011-06-08, 22:03:32
optional parameters of "component" - by bugman - 2011-06-08, 22:23:43
optional parameters of "component" - by mvlcek - 2011-06-18, 07:23:05
optional parameters of "component" - by mvlcek - 2011-06-18, 21:33:07
optional parameters of "component" - by ccagle8 - 2011-06-20, 09:10:54
optional parameters of "component" - by mvlcek - 2011-06-20, 16:27:53
optional parameters of "component" - by mvlcek - 2011-06-20, 19:36:30
optional parameters of "component" - by Zegnåt - 2011-06-20, 19:52:03
optional parameters of "component" - by mvlcek - 2011-06-20, 20:45:03
optional parameters of "component" - by mvlcek - 2011-06-20, 23:55:27
optional parameters of "component" - by mvlcek - 2011-06-21, 05:28:08



Users browsing this thread: 1 Guest(s)