Final is about having immutable data. Immutable doesn't mean that it's a system wide constant, it means that it's referentially pure in its scope.
On 29 Jun 2017 11:05 AM, "li...@rhsoft.net" <li...@rhsoft.net> wrote: > > > Am 29.06.2017 um 04:50 schrieb Kalle Sommer Nielsen: > >> 2017-06-28 20:46 GMT+02:00 David Rodrigues <david.pro...@gmail.com>: >> >>> The "final" keyworks make a "local scope" variable value "blocked to >>> rewrite" after instantiate it. >>> Okay, it sounds like a "const", and it is, but "not as we known it". >>> >> >> I get that, but I still don't understand why you would forcefully need >> it to be a variable still then if you know the value is gonna be >> constant, of course besides global visibility or in iterations >> > > because constants are expensive in PHP when "define()" is a function call > and "const" is very limited for no good reason > > "no good reason" because if it really would be compile time the following > won't work and so why can't you use 'const' within a if-statement when you > in fact can CONCAT two with define() set constant which are part of a > if-statement themself > ____________________________________________________ > > if(PHP_SAPI !== 'cli') > { > define('MY_PHP_SELF', $_SERVER['SCRIPT_NAME']); > define('rh_serverurl', PROTOCOL_PREFIX . MY_SERVER_NAME . $rh_port); > } > else > { > define('MY_PHP_SELF', '/' . basename($_SERVER['SCRIPT_NAME'])); > define('rh_serverurl', 'http://localhost'); > } > const rh_phpself = rh_serverurl . MY_PHP_SELF; > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >