i was looking at a tutorial from ZendCasts where i wondered about the code he used. a simplified version below
class TestClass {
private $_var;
private static function getDefaultView() {
if (self::$_var === null) { ... } // this is the line in question
}
}
i wonder why is something like isset(self::$_var) not used instead?
when i use self:: i need the $ sign to refer to variables? i cant do self::_var?
how does == differ from ===
These are several questions.
It’s indifferent. The advantage of using
issetis that a notice is not emitted if the variable ins’t defined. In that case,self::$_varis always defined because it’s a declared (non-dynamic) property.issetalso returns false if the variable isnull.Note that this is not a regular variable, it’s a class property (hence the
self, which refers to the class of the method). Yes, except if this is a constant. E.g.:This has been asked multiple times in this site alone.