Introducing pragmas into PHP?
| From: | Terry Ellison | Date: | Sun, 08 Dec 2013 17:04:33 +0000 |
| Subject: | Introducing pragmas into PHP? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-70535@lists.php.net to get a copy of this message | ||
Hi,
We have ongoing debates about the pull between BC behaviour and wanting to tidy up / optimize performance etc. And often BC for bizarre coding practices means that there is a performance penalty for everyone else. A common way of doing this in C etc. is the use of compiler pragmas, but such a change would in itself be not BC and INI parameters are too blunt an instrument here as these are set at runtime or globally as a PER_INI_USER etc. They can't impact the current source being compiled, and they can't be conveniently namespace-specific.
I am suggestion the overload of constants of the form PHP_PRAGMA_XXX to define PHP / Zend compiler / executor behaviours. This approach would be BC to 5.3 unless, of course, the application already used PHP_PRAGMA_* constants, in which case we might also need an allow_php_pragmas INI parameter to globally enable/disable their interpretation.
As a small example:
namespace fred;
echo \strlen("DDDD");
generates different .
SEND_VAL 'DDDD' DO_FCALL 1 $0 'strlen'and different (slower) opcode if you omit the \
INIT_NS_FCALL_BY_NAME 'strlen' SEND_VAL 'DDDD' DO_FCALL_BY_NAME 1 $0Whilst most sane projects would have a simple programming standard which basically says "Don't override builtin functions", the odd one might for various reasons allow this. This practice can significantly complicate optimization for performance (see https://bugs.php.net/bug.php?id=64346). I've seen namespace-based project where all builtins have the explicit global \ prefix. IMO, yukkk. So my suggestion is that we allow the programmer to issue a pragma to inform compiler and runtime handling, so in this case for example, namespace fred; const PHP_PRAGMA_ALLOW_OVERRIDE_BUILTINS=false; echo strlen("DDDD"); would define the constant fred\PHP_PRAGMA_ALLOW_OVERRIDE_BUILTINS and also have the desired compile-time and runtime effect. Alternatively the corresponding global constant \PHP_PRAGMA_ALLOW_OVERRIDE_BUILTINS could be set to false and individual namespaces could set the corresponding namespace constant to true. Thoughts and comments? Terry Ellison