note 130045 added to language.oop5.static
| From: | 1998shivammishra167@gmail.com | Date: | Thu, 20 Feb 2025 12:22:07 +0000 |
| Subject: | note 130045 added to language.oop5.static | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221869@lists.php.net to get a copy of this message | ||
//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::)
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 45.115.104.151)
----
Manual Page -- https://php.net/manual/en/language.oop5.static.php
Edit -- https://main.php.net/note/edit/130045
Del: integrated -- https://main.php.net/note/delete/130045/integrated
Del: useless -- https://main.php.net/note/delete/130045/useless
Del: bad code -- https://main.php.net/note/delete/130045/bad+code
Del: spam -- https://main.php.net/note/delete/130045/spam
Del: non-english -- https://main.php.net/note/delete/130045/non-english
Del: in docs -- https://main.php.net/note/delete/130045/in+docs
Del: other reasons-- https://main.php.net/note/delete/130045
Reject -- https://main.php.net/note/reject/130045
Search -- https://main.php.net/manage/user-notes.php