If you’re using a class, it would be
class MyShortcode {
static $instance = 0;
function __construct($args = array()) {
add_action( 'init', array(&$this, 'init') );
}
function init() {
add_shortcode('myshortcode', array(&$this, 'shortcode'));
}
static function shortcode($atts) {
//this is the code of your shortcode
// you can increment your counter
self::$instance++;
}
}