2010/5/19 Tjerk Anne Meesters <datib...@php.net>

> On Wed, May 19, 2010 at 5:52 PM, Frederic Hardy
> <frederic.ha...@mageekbox.net> wrote:
> > Hello !
> >>
> >> AFAIK class constants are optimized for speed and therefore don't
> >> support expressions; don't expect this to change any time soon ;-)
> >>
> >>> Is there any feature request about constant and expression ?
> >>> I would like to write something like that :
> >>>
> >>> <?php
> >>>
> >>> namespace foo\bar\directories {
> >>>    const tmp = __DIR__ . '/tmp';
> >>> }
> >>>
> >>> ?>
> >
> > So the best solution is something like <?php
> > define('foo\bar\directories\tmp', __DIR__ . '/tmp'); ?>...
> > It 's strange that "define()" function can do something that the "const"
> >  keyword can't do, even if "const" keyword evaluation is done at
> compilation
> > time and "define()" evaluation is done at runtime.
>
> That's why there's a cost penalty to using define().
>
> I wrote a small article that gives an idea of the speed differences:
> http://shwup.blogspot.com/2010/04/about-constants.html
>
>
> >
> > Best regards,
> > Fred.
> >
> > --
> > ========================================================================
> > Frédéric Hardy : Architecte d'application/Admin. système/Ergonome
> >        Status : En recherche d'emploi
> > ========================================================================
> >
> >
>
>
>
> --
> --
> Tjerk
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

How about extending the usage of the 'final' keyword to support a java-like
syntax?

class Foo {
   private static final $bar = 'ex' . 'pression';
   // and also
   private final $baz = 'another'.'expression';
   // and maybe
   private final $inTheCtor;

   public function __construct($aValue) {
       $this->inTheCtor = $value;
   }
}

Reply via email to