• Hi
    I put into a Code Snippet record function pageLists($list). I set for that record priority 1.

    When I called the function in another Code Snippet record, which has priority 7.

    But when I tried to save the record, which calls the function, Code Snipper claimed that function doesn’t exist.

    IMO this is wrong behavior because function in a record with priority 1 should be available in record, which has priority 7. IMO priority checking doesn’t work.

    When I put the function to the same record, where I call the function, there was no problems.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter tapiohuuhaa

    (@tapiohuuhaa)

    If Code Snippet doesn’t find the function, which has been called, this error behavior can be fixed this way:

    if(function_exists(‘pageLists’)){
    $address = pageLists($list);
    $y=0;
    foreach ($address as $value) {
    if($y==0){$blogi=$value;}
    elseif($y==1){$articles=$value;}
    elseif($y==3){$muut=$value;}
    elseif($y==4){$articles3=$value;}
    elseif($y==5){$ristikot=$value;}
    elseif($y==6){$videot=$value;}
    elseif($y==7){$tag=$value;}
    $y++;
    }
    }
    }

    Anyway this is needed only because Code Snippet can’t reliable check if function really exists or not.

    I would be nice, if the Code Snippet could better check if function is available.

    In this case the function, which was checked was another Code Snippet with lower priority. The function really was available and defined, but for some weird reason Code Snippet didn’t find it.

    Thread Starter tapiohuuhaa

    (@tapiohuuhaa)

    It is for me difficult to understand, why Code Snippe couldn’t check priorities, when it saves Code Snippets.

    My suggestions.

    1. If the snippet has references own functions, it would check if there is in another snippets with lower priority called function. If there doesn’t exist, Code Snippet could at least warn about possible missing function.
    2. Code Snippet would force setting higher priority if it finds reference to functions, which has the same or higher priorities.

    Then for example function call $settings=getLayoutSettings($settings); is in a snippet, which has priority “7” would be valid only, if function getLayoutSettings() has been defined in the same snippet or in a snippet, which has priority 0-6.

    Then it would not be necessary to add function_exists() like this

    if(is_user_logged_in() && function_exists(‘getLayoutSettings’)){

    In this case own function, which has been defined in another snippet really exists and is available in this connection would in principle not need to check existence with function_exists, if Code Snippet would not work buggy.

    Indeed it is not a big problem to add in principle unnecessary check with function_exists

    Thread Starter tapiohuuhaa

    (@tapiohuuhaa)

    Indeed this is not the worst bug. If Code Snippet doesn’t find existing function, it allows to define function with the same name. It doesn’t help that priorities are OK. This is very nasty.

    Plugin Author Shea Bunge

    (@bungeshea)

    There’s no such thing as ‘priority checking’. The snippet priority only specifies the order that snippets are executed in when executed as a group.

    This means that priorities should not be used as some sort of dependency management system. The reason why you might see snippets executed out of priority order is because validating whether a snippet’s code contains an errors disrupts the standard execution order momentarily.

    The solution to this is to write snippets which won’t cause an error if a different snippet is momentarily unavailable. Any snippets which depend on classes or functions defined in other snippets should take the necessary precautions using functions such as function_exists and class_exists.

    Plugin Author Shea Bunge

    (@bungeshea)

    The solutions that you propose would require maintaining an index of functions previously defined in snippets. This would be difficult to create, as parsing PHP code as text is a little unreliable, and other methods of doing so would require evaluating the code itself, which can cause other complications.

    This index would then need to be stored somewhere and updated whenever a snippet is edited or activated. At this stage, I feel this additional functionality would be overly complex for the small benefit it would provide.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Priority checking error?’ is closed to new replies.