class MyClass { public static $myStaticVar = "Hello, World!"; public static function myStaticMethod() { echo self::$myStaticVar; } } echo MyClass::$myStaticVar; // Output: Hello, World! MyClass::myStaticMethod(); // Output: Hello, World!
class StringUtils { public static function isValidEmail($email) { // Validation logic here } public static function formatPhoneNumber($number) { // Formatting logic here } } if (StringUtils::isValidEmail("example@example.com")) { echo "Valid email address"; } echo StringUtils::formatPhoneNumber("123-456-7890"); // Output: (123) 456-7890In this example, we have defined a class named StringUtils that provides static methods for validating email addresses and formatting phone numbers. We can access these methods without the need of creating an instance of the class, making it easier to use these utility methods in our code.