We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20394
    • 134 Posts
    First define a new class which will use the global variable $modx and the magic functions __call(), __set() and __get() :
    class MyDocumentParser{
    
    //put here your new variables
    //put here your new functions
    //put here your new definitions of old functions
    
    public function __call($name, $arguments){
    global $modx;
    if(count(arguments==1)) return $modx->$name($arguments[0]);
    else return $modx->$name($arguments);
    }
    public function __set($var, $value){
    global $modx;
    $modx->$var=$value;
    }
    public function __get($var){
    global $modx;
    return $modx->$var;
    }
    
    }

    Then you create an object :
    $modx2=new MyDocumentParser();


    You can use all the API of $modx with $modx2, and you can define new functions for $modx2 without changing the code of MODx.
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: mrcou at Sep 08, 2006, 08:45 AM

      First define a new class which will use the global variable $modx and the magic functions __call(), __set() and __get() :
      class MyDocumentParser{
      
      //put here your new variables
      //put here your new functions
      //put here your new definitions of old functions
      
      public function __call($name, $arguments){
      global $modx;
      if(count(arguments==1)) return $modx->$name($arguments[0]);
      else return $modx->$name($arguments);
      }
      public function __set($var, $value){
      global $modx;
      $modx->$var=$value;
      }
      public function __get($var){
      global $modx;
      return $modx->$var;
      }
      
      }

      Then you create an object :
      $modx2=new MyDocumentParser();


      You can use all the API of $modx with $modx2, and you can define new functions for $modx2 without changing the code of MODx.

      Interestingly clever; though I think you’ll find the ability to extend the MODx class itself to accomplish the same thing without the trickery very soon, and in both PHP 4 and 5...