Re: Introducing pragmas into PHP?
| From: | Terry Ellison | Date: | Sun, 08 Dec 2013 18:07:52 +0000 |
| Subject: | Re: Introducing pragmas into PHP? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70537@lists.php.net to get a copy of this message | ||
On 08/12/13 17:14, Alexey Zakhlestin wrote:
namespace fred; const PHP_PRAGMA_ALLOW_OVERRIDE_BUILTINS=false; echo strlen("DDDD"); define() is a runtime function implemented by Zend/zend_builtin_functions.c:ZEND_FUNCTION(define). The constant which is defines is not available until the DO_FCALL_BY_NAME opcode is itself executed sometime *after* the compile of the current source completes. const is a syntactic construct that can be intercepted in zend_compile.c, etc., and therefore can condition the remainder of the compile of that source. That's what pragmas do. However, you are quite correct that: define('fred\PHP_PRAGMA_ALLOW_OVERRIDE_BUILTINS', false); include "some_other_php_file_in_namespace_fred.php"; ... would set the pragma for subsequent source scripts in the "fred" namespace, if we adopted this convention. Hope this helps. TerryI 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.we already have declare() for this purpose exactly. http://docs.php.net/declare it might make sense to use it for more things Alexey, perhaps you missed the subtlety of my example: