Jump to content

[SOLVED] basic question about operators "::"


mare70

Recommended Posts

It's not the same as ->.  It's a scope resolution operator.  It's often used to perform a method of a given class in a static context, but it's also used when referring to self::, parent::, etc.  For example:

 

class Database {

    protected $instance;

    protected function __construct() {

        //do some stuff

    }

    public static function getInstance() {

       if (!$this->instance) {

              $this->instance = new self();

       }

       return $this->instance;

   }

}

 

Then you could do:

 

$db = Database::getInstance();

It's used in a computer paradigm called object-oriented programming.  There's plenty of books and articles and tutorials on the subject.  There are even 3 on this very site on the home page that are pretty well-written.  Start with those (starting with number 1, of course).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.