We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37405
    • 2 Posts
    I am converting some of my php functions to run in MODX. Many work fine. One has a problem I am having trouble solving. The code in question creates <div> blocks with unique ids so they can be hidden and shown by Javascript code.

    I have created some simple routines to isolate the area where I need some help. There are two functions, one returns a value, the other bumps it. As included in a standard PHP page all versions work. When called in MODX document via snippets the value is displayed at its highest in all places. I have tried running cached and uncached at all levels. Nothing helps.
    ------------------------------------------------------------------------
    Output from standard PHP page, note the values are different:
    Changing a static variable.

    STATIC: 22
    Bump value.
    Value after bump.
    STATIC: 33
    Bump value.
    Value after bump.
    STATIC: 44
    ------------------------------------------------------------------------
    Output from MODX, note the values are the same.
    Changing a static variable.

    STATIC: 44
    Bump value.44
    Value after bump.
    STATIC:44
    Bump value.44
    Value after bump.
    STATIC:44
    ------------------------------------------------------------------------
    I have read much about the order and timing of execution when cached and uncached. Shouldn't this work?
    ------------------------------------------------------------------------
    The php functions, used by both the simple PHP page and MODX.
    bump_value and get_value functions at end call one of the three versions, X or Y or Z. All work with the PHP page. None work with MODX.
    static.php
    <?php
    global $g_static;
    $g_static = 22;

    function bump_valueX() {
    global $g_static;
    $g_static += 11;
    return $g_static;
    }

    function get_valueX() {
    global $g_static;
    return $g_static;
    }

    function bump_valueY() {
    $_SESSION["value"] += 33;
    return $_SESSION["value"];
    }

    function get_valueY() {
    if ( !isset($_SESSION["value"] )) {
    $_SESSION["value"] = 44;
    }
    return $_SESSION["value"];
    }

    function bump_valueZ() {
    $GLOBALS['static_value'] += 55;
    return $GLOBALS['static_value'];
    }

    function get_valueZ() {
    if ( !isset($GLOBALS['static_value'] )) {
    $GLOBALS['static_value'] = 66;
    }
    return $GLOBALS['static_value'];
    }

    function bump_value() { return bump_valueX(); }
    function get_value() { return get_valueX(); }
    ?>
    ------------------------------------------------------------------------
    The simple html that works:
    static_page.php
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>
    PHP static test
    </title>
    </head>
    <body>
    <?php
    session_start();
    include "static.php";
    ?>
    <h3>Changing a static variable. </h2>
    STATIC: <?php echo get_value(); ?>

    Bump value.

    <?php bump_value(); ?>
    Value after bump.

    STATIC: <?php echo get_value(); ?>

    Bump value.

    <?php bump_value(); ?>
    Value after bump.

    STATIC: <?php echo get_value(); ?>

    </body>
    </html>
    ------------------------------------------------------------------------
    MODX resource content version of above:
    [[includeStatic]]
    Changing a static variable.

    STATIC: [[!getStatic]]
    Bump value.[[!bumpStatic]]
    Value after bump.
    STATIC:[[!getStatic]]
    Bump value.[[!bumpStatic]]
    Value after bump.
    STATIC:[[!getStatic]]
    ------------------------------------------------------------------------
    includeStatic snippet:
    <?php
    include "static.php";
    ------------------------------------------------------------------------
    getStatic snippet:
    <?php
    echo get_value();
    ------------------------------------------------------------------------
    bumpStatic snippet:
    <?php
    echo bump_value();
    ------------------------------------------------------------------------
    Can anyone tell me how to make this work or tell me there is a limitation with MODX?
      • 37405
      • 2 Posts
      Some of the code seems to have been filtered out by the posting process.
      I will try an attachment.