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.]