Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #5803
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: const var, self:: or static:: |
| Date | 2012-05-02 07:13 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <jnr4sp$78d$1@dont-email.me> (permalink) |
| References | <a0ce19Fb48U1@mid.individual.net> |
On 5/2/2012 5:45 AM, Simon wrote:
> If I have something like...
>
> //
> class MyClass
> {
> const MY_CONST = 10;
>
> ...
> }
> //
>
> Inside the class, is it 'better' to use self::MY_CONST or static::MY_CONST?
>
> I say 'better' because it works in both cases.
>
> Or is it just a personal choice.
>
> Thanks
>
> Simon
There is no "better" - it depends on what you want. There is no
difference when you have a single class like this, but there can be when
you have a derived class. self:: will always call a static function in
the base class, while static:: will call a static function in the
derived class (I've never tried it with constants, but the same may be
true).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
const var, self:: or static:: Simon <bad@example.com> - 2012-05-02 11:45 +0200
Re: const var, self:: or static:: Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-02 07:13 -0400
Re: const var, self:: or static:: "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-05-02 17:25 +0200
Re: const var, self:: or static:: Michael Fesser <netizen@gmx.de> - 2012-05-02 19:55 +0200
csiph-web