note 120083 added to language.oop5.constants
| From: | jimmmy dot chief at gmail dot com | Date: | Tue, 25 Oct 2016 14:57:40 +0000 |
| Subject: | note 120083 added to language.oop5.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206952@lists.php.net to get a copy of this message | ||
Hi, i would like to point out difference between self::CONST and $this::CONST with extended class.
Let us have class a:
<?php
class a {
const CONST_INT = 10;
public function getSelf(){
return self::CONST_INT;
}
public function getThis(){
return $this::CONST_INT;
}
}
?>
And class b (which extends a)
<?php
class b extends a {
const CONST_INT = 20;
public function getSelf(){
return parent::getSelf();
}
public function getThis(){
return parent::getThis();
}
}
?>
Both classes have same named constant CONST_INT.
When child call method in parent class, there is different output between self and $this usage.
<?php
$b = new b();
print_r($b->getSelf()); //10
print_r($b->getThis()); //20
?>
----
Server IP: 72.52.91.14
Probable Submitter: 78.156.159.147
----
Manual Page -- http://php.net/manual/en/language.oop5.constants.php
Edit -- https://master.php.net/note/edit/120083
Del: integrated -- https://master.php.net/note/delete/120083/integrated
Del: useless -- https://master.php.net/note/delete/120083/useless
Del: bad code -- https://master.php.net/note/delete/120083/bad+code
Del: spam -- https://master.php.net/note/delete/120083/spam
Del: non-english -- https://master.php.net/note/delete/120083/non-english
Del: in docs -- https://master.php.net/note/delete/120083/in+docs
Del: other reasons-- https://master.php.net/note/delete/120083
Reject -- https://master.php.net/note/reject/120083
Search -- https://master.php.net/manage/user-notes.php