LonghornPHP 2026

Voting

: zero plus eight?
(Example: nine)

The Note You're Voting On

1998shivammishra167 at gmail dot com
1 year 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