note 114945 added to language.oop5.constants
| From: | enrico_kaelertatkabelmaildotcom | Date: | Thu, 01 May 2014 19:05:53 +0000 |
| Subject: | note 114945 added to language.oop5.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199399@lists.php.net to get a copy of this message | ||
additional to tmp dot 4 dot longoria at gmail dot com ´s post:
quote:
it's possible to declare constant in base class, and override it in child,
/quote
Its not that we overwrite them.
Its more that each got its own:
<?php
abstract class dbObject
{
const TABLE_NAME='undefined';
}
class dbPerson extends dbObject
{
const TABLE_NAME='persons';
public static function getSelf()
{
return self::TABLE_NAME;
}
public static function getParent()
{
return parent::TABLE_NAME;
}
}
class dbAdmin extends dbPerson
{
const TABLE_NAME='admins';
public static function getSelf()
{
return self::TABLE_NAME;
}
public static function getParent()
{
return parent::TABLE_NAME;
}
}
echo '<pre>
im class dbPerson{} and this is my:
self TABLE_NAME: '.dbPerson::getSelf().' // persons
parent TABLE_NAME: '.dbPerson::getParent().' // undefined
im class dbAdmin{} and this is my:
self TABLE_NAME: '.dbAdmin::getSelf().' // admins
parent TABLE_NAME: '.dbAdmin::getParent().' // persons
';
?>
or more readable:
<?php
class ParentClass
{
const CONSTANT = 'CONST_PARENT';
}
class A extends ParentClass
{
const CONSTANT = 'CONST_A';
public static function getSelf()
{
return self::CONSTANT;
}
public static function getParent()
{
return parent::CONSTANT;
}
}
echo '<pre>
im class A{} and this is my:
self CONSTANT: '.A::getSelf().' // CONST_A
parent CONSTANT: '.A::getParent().' // CONST_PARENT
';
?>
----
Server IP: 72.52.91.14
Probable Submitter: 95.91.112.213
----
Manual Page -- http://php.net/manual/en/language.oop5.constants.php
Edit -- https://master.php.net/note/edit/114945
Del: integrated -- https://master.php.net/note/delete/114945/integrated
Del: useless -- https://master.php.net/note/delete/114945/useless
Del: bad code -- https://master.php.net/note/delete/114945/bad+code
Del: spam -- https://master.php.net/note/delete/114945/spam
Del: non-english -- https://master.php.net/note/delete/114945/non-english
Del: in docs -- https://master.php.net/note/delete/114945/in+docs
Del: other reasons-- https://master.php.net/note/delete/114945
Reject -- https://master.php.net/note/reject/114945
Search -- https://master.php.net/manage/user-notes.php