# declaring classes as static or final

- Thread: https://externals.io/message/13065
- Original archive: https://news-web.php.net/php.internals/13065
- Started by Andrey Hristov on 2004-09-29T10:01:36+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13065 — Andrey Hristov — 2004-09-29T10:01:36+00:00

URL: https://externals.io/message/13065#13065

Michael Virnstein wrote:

> > […]
 >
 >
 >
 > Cannot find it in the docs.
 > http://www.php.net/manual/en/language.oop5.final.php doesn't seem to have
 > any comments on that.
 > I'm not at home at the moment, so i couldn't try, but are you really sure
 > that final CLASSES are supported?
 > You're not confusing it with final METHODS, right?
 >
andrey@vivaldi:~> php -r 'final class a{} class b extends a{}'

Fatal error: Class b may not inherit from final class (a) in Command line code on line 1



 >
 > A good example for a static class imo, would be e.g. PEAR's DB Class. The
 > DB-Class itself doesn't need to be instantiate,
 > it simply works as factory and has some functions to check stuff. that'd be
 > a class that i would define as
 > "final static class DB {}". The class should not be extended and should not
 > containt non static methods or attributes. Sure it isn't
 > a big deal, if ppl are instantiating the DB Class, but it only has static
 > methods and instantiating it wouldn't make any sense.
 >
Make the constructor private and the class final. No instance will be available,
and no inheritance possible. Methods has to work, and therefore they may not
expect to have $this available in them.

Andrey
