[TYPO3-core] RFC #12066: Code cleanup: Add some constants
Sigfried Arnold
s.arnold at rebell.at
Wed Mar 3 18:02:19 CET 2010
Am 21.02.2010 17:31, schrieb Oliver Klee:
> The main point of this is to improve code readability [...]
This can be done with coding guidelines.
> $foo = $salutation . LF . $body;
>
> ... instead of this:
>
> $foo = $salutation . chr(10) . $body;
Why not just using PHP internal double quoted strings?
(see http://php.net/manual/en/language.types.string.php)
$foo = "$salutation\n$body";
or
$foo = $salutation . "\n". $body;
> Another side-effect will be improved performance because chr(10) is a
> function call while LF is not.
Your solution points to a constant identifier. They use a scalar data
type (in your case) and use "way more" resources (since they need to be
kept in the global scope) than using no variable, constant for function
at all. PHP internal escape charactes, wich are designed for exactly
this purpose, are recommended.
Else: a function call is not a performance argument. Such trivial
functions usualy reached directly to C functions and take barely no
time. Also the "way more" argument i brought in is nothing more than hot
air - it goes in the direction of micro optimization and should be
negligible.
> (And I'm already using those constants in my own extensions and would
> like to get them into the core so I can drop them from my library
> extension.)
Just use PHP escapes wich is very common in PHP enviroments.
Constants should always represent enviroment variables - like path to
document root, settings for database access (well - $typo_db_host and
his brothers should be constants instead of variables) and stuff like
this. But not a generic placeholder.
More information about the TYPO3-team-core
mailing list