CKTIS / PHP
Class scope resolution (::)
Select a class constant, static property or static method through its class scope.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
ClassName::CONSTANT
ClassName::method()
ClassName::$propertySelect a class constant, static property or static method through its class scope. A class constant does not require an instance. Inside an inherited method, self:: selects the declaring class, whereas static:: selects the called class through late static binding. The latter sees the overridden constant in a subclass.
ClassName::CONSTANT
ClassName::method()
ClassName::$property
[2,5]
Examples
<?php
class BaseRate { public const RATE = 2; public static function forCall(): int { return static::RATE; } }
class PeakRate extends BaseRate { public const RATE = 5; }
echo json_encode([BaseRate::RATE, PeakRate::forCall()]);
Result
[2,5]