Refer to the static method. PHP Code example open

Refer to the static method. PHP Code example

class Math{
	const PI = 3.14;

	public static function rangeArea(float $r) : float{
// in the body of the static method to access the constant use self::name
		return $r * $r * self::PI;
	}

	public static function rangeLength(float $r) : float{
		return 2 * $r * self::PI;
	}
}

We can resort to the static method without creating a class object

echo Math::rangeArea(5) 
echo Math::rangeLength(5) 

self:: use for early static binding there is also late static binding to get it use static::

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation