We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10152
    • 156 Posts
    Hello,

    at the top of a template, berore html headers I call my [[snippet]].
    Content of the snippet :
    <?php
    require('/homez.305/user/www/assets/user/extension/treatments.php');
    ?>

    Content of treatments.php :
    <?php
    
    function fakeFunction(){
    echo 'ooo';
    }
    ?>
    


    This is enough to stop the script :

    Fatal error: Cannot redeclare fakefunction() (previously declared in /homez.305/mysite/www/assets/user/extension/generalFunctions.php:8) in /homez.305/mysite/www/assets/user/extension/generalFunctions.php on line 11


    Modx 1.0 . Yams installed


    I have antoher question, is it possible that if I define $test=’ok’; in a snippet, the variable to be reachable in others snippets ? so I do not have to require() twice the config.php for programs that are called in two times.

    Thanks for your help


      • 5340
      • 1,624 Posts
      can you try the following:
      
      <?php
      require('/homez.305/user/www/assets/user/extension/treatments.php');
      return fakeFunction();
      ?>
      
      
      
      


      with
      <?php
      
      function fakeFunction(){
      return 'ooo';
      }
      
      ?>
      


        • 10152
        • 156 Posts
        Fatal error: Cannot redeclare fakefunction() (previously declared in /homez.305/...extension/generalFunctions.php:3) in /homez.305.../extension/generalFunctions.php on line 4
          • 5340
          • 1,624 Posts
          try

          include_once(’assets/user/extension/treatments.php’);

            • 10152
            • 156 Posts
            Yes it works, but is it normal that a snippet is called twice ?

            I don’t like to use include_once for some reasons but if I have no other choice.

            Thanks smiley
              • 5340
              • 1,624 Posts
              I am not sure what’s happening. Maybe you call the snippet twice.
              If not the coding team might clarify this issue.