PHP 8.5.0 Alpha 4 available for testing

Voting

: max(nine, five)?
(Example: nine)

The Note You're Voting On

1998shivammishra167 at gmail dot com
5 months ago
//Difference Between self:: and static::

<?php
class A {
protected static
$name = "Class A";

public static function
getName() {
return
self::$name; // Uses class A's property
}

public static function
getNameStatic() {
return static::
$name; // Uses the property from the child class
}
}

class
B extends A {
protected static
$name = "Class B";
}

echo
B::getName(); // Output: Class A (Because of self::)
echo B::getNameStatic(); // Output: Class B (Because of static::)

?>

<< Back to user notes page

To Top