Re: Introducing pragmas into PHP?

From: Date: Sun, 08 Dec 2013 18:12:21 +0000
Subject: Re: Introducing pragmas into PHP?
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70538@lists.php.net to get a copy of this message
Hello, On Sun, Dec 8, 2013 at 4:07 PM, Terry Ellison <ellison.terry@gmail.com> wrote: > On 08/12/13 17:14, Alexey Zakhlestin wrote: >>> >>> 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. >> >> 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: > > > 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. Terry Looks like you misread Alexey's post. He was talking about declare construct, not define() function. -- Regards, Felipe Pena

« previous php.internals (#70538) next »