Re: Re: RFC: mark functions as const for possible optimizations

From: Date: Sun, 16 Sep 2007 23:05:23 +0000
Subject: Re: Re: RFC: mark functions as const for possible optimizations
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-32349@lists.php.net to get a copy of this message
Hi Nuno, On Sun, 2007-09-16 at 20:02 +0100, Nuno Lopes wrote: > > >My proposal is the following: > > >some functions when fed with constant arguments always return a constant > > >value, too. e.g.: > > >strlen('abcd') === 4. > > > > I like the general idea. > > > > Would there be some caveats with stuff like this if it is possible to > > change the charset at runtime? > > > > I guess it is important to be aware of whether a function is affected > > by different settings (and if these settings can be changed at > > runtime) to conclude if a function really is deterministic at this > > level. > > uhm, damn, right. strlen() wasn't a good example.. my bad, sorry :S > Anyway, you got the idea :) Nothing wrong with strlen as far as I can tell: - In PHP 5 we only have binary strings so strlen() works independent from any charsets and encodings by just counting bytes. - In PHP 6 we know - assuming the parameter is a constant string - the encoding at compile time, therefore it could be used. The only edge-case I see is if somebody uses mbstring.func_overload and overwrites strlen() johannes

« previous php.internals (#32349) next »