On 29 November 2019 19:48:37 GMT+00:00, Claude Pache <claude.pa...@gmail.com> wrote: >I don’t think it should be a declare() directive, because: > >* It changes incompatibly the meaning of valid (non-error-throwing) >code. The current existing declare() directive, >declare(strict_types=*), has the nice property that code that does not >throw error in *both* modes does not change behaviour. > >* When you want to know the FQN of a random identifier, it is necessary >and sufficient to look at the “namespace” and the “use” declarations. >With `use function *`, that won’t change. With >`declare(lookup_functions_somewhere)`, you have now to look at an >additional place.
Hi Claude, I understand both of these points, but both are subtly inaccurate. 1) strict_types is not the first or only declare directive. Declaring an encoding fundamentally changes the meaning of a source file; probably it would be invalid in a different encoding, but errors are not the primary purpose of the directive. Declaring a value of "ticks" actually changes the *runtime* behaviour of the code. The manual defines declare vaguely as "used to set execution directives", so it's not particularly clear to me that changing namespace resolution would be outside of its purpose. 2) The existing fallback to global scope means that looking at the use statements of a file is not sufficient to resolve the ambiguity of an unprefixed function name. Indeed, the same line of code can execute two different functions within a running program if the namespaced function is defined at the right time. I'm generally not convinced that beginning the special directive with the word "use" automatically makes it easier to find or understand. Given some code mentioning "strpos", you wouldn't be able to scan the list of use statements for the word "strpos", you'd have to understand that there are two modes of execution, and look for a line that switches between those modes. I would expect that if it was worded as a use statement, coding standards would place it at the top of that list, so we're talking about the difference between: declare(strict_types=1); namespace Foo; use global functions; ... and declare(strict_types=1); declare(global_functions=1); namespace Foo; ... Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php