I have been stepping up my PHP game lately. Coming from JavaScript, I've found the object model to be a little simpler to understand.
I've run into a few quirks that I wanted some clarifying on that I can't seem to find in the documentation.
When defining classes in PHP, you can define properties like so:
class myClass {
public $myProp = "myProp";
static $anotherProp = "anotherProp";
}
With the public variable of $myProp
we can access it using (assuming myClass
is referenced in a variable called $myClass
) $myClass->myProp
without the use of the dollar sign.
We can only access static variables using ::
. So, we can access the static variable like $myClass::$anotherProp
with a dollar sign.
Question is, why do we have to use dollar sign with ::
and not ->
??
EDIT
This is code I would assume would work (and does):
class SethensClass {
static public $SethensProp = "This is my prop!";
}
$myClass = new SethensClass;
echo $myClass::$SethensProp;