We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I'm curious about how well other editors handle certain kinds of programming errors, and I wanted to demonstrate the value of having a good code editor. There are about 20 serious programming errors in this little bit of code (depending on how you count). See how many you can spot with the naked eye (and note how long it takes you), then see how many your code editor finds:

    <?php
    
    class MyClass {
        public $modx;
        public $props;
        protected $color;
        protected $size;
    
        function __construct(&$modx, &$scriptProperties) {
            $this->modx =& $modx;
            $this->props & = $scriptproperties;
        }
    
        public function myMethod($size, $color) {
            $this->size = $size;
            $color = 'Red';
            $this - > color = $color;
    
            $maxsize == $modx->getOption('maxSize', $props, 50));
            if ($size > = $maxSize) {
                $finalSize = 50;
            }
            return $finalSize
        }
    }
    include 'c:\xampp\htdocs\addons\core\model\modx\modx.class.php';
    $modx = new modX();
    $modx->initialize('mgr');
    $object = new MyClass($modx);
    $size = $object->size;
    $color = $object->color;
    $finalColor = $object->myMethod($size, $colour);
    $output .= $finalcolor;
    return $ouput;


    PHP will throw errors for some of them if your error_reporting level is high enough, but many would go right past it in a typical configuration. Even with those caught by PHP, it's a whole lot less time-consuming to catch them all in the editor rather than running the code over and over and fixing them one at a time.

    One reason I did this now it that for the next week or so, PhpStorm (which catches all of them) is on sale for $49 http://www.jetbrains.com/phpstorm/buy/index.jsp


    ------------------------------------------------------------------------------------------
    PLEASE, PLEASE specify the version of MODX you are using.
    MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years ago.]
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 3749
      • 24,544 Posts
      BTW, I pasted the code into PhpEd 5.5 and it highlighted one error. I don't have a copy of NetBeans any more, but I'm curious how it would do.



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 26903
        • 1,336 Posts
        Screenshot from netbeans, picks up the syntax errors and unused vars OK
          Use MODx, or the cat gets it!
          • 3749
          • 24,544 Posts
          Looks like it got about half of them. I'll try to post the PhpStorm screenshot later.


          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3749
            • 24,544 Posts
            Here is the screenshot from PhpStorm. I wish I could show you the hover help for each error.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting