What is the difference between accessing a class method via → and via ::?
->designed to access the properties and methods of created objects. ::- This is access to static methods, constants, or overridden methods.
->
::
For more information:
:: It is used to access static methods or attributes, so you do not need to instantiate an object of the containing class.
-> used to access methods or attributes of created objects.
-> ( , , / ).
:: - , , , .
:
class Mustang { var $gallons = 12; // gallons public function getFuel() { return $this->gallons; } public static function getEngine() { return "V8"; } } $mustang = new Mustang(); // creating an instance echo $mustang->getFuel(); // retrieve the fuel (instance, _this_ mustang) echo Mustang::getEngine(); // echo a stat about Mustangs in general (static)
"", () ( ->).
-, - , , ( V8, ::).
. :: .... ( ), -. , . , . ; . ( , - , ->
, ->? , . , . :
$john = new User(); //create the object $john->age = 10; //accessing an object property $age = $john->getAge(); //accessing an object method