On 23/09/2016 12:41, Nikita Popov wrote:
Hi internals!
I'd like to propose the ability of specifying declare directives like
"strict_types" at the namespace level.
The broader context of this proposal is to provide a simple and usable
mechanism that will allow developers to opt-in to stricter language
semantics on a per-library (or more specifically, per-namespace) basis,
thus alleviating backwards compatibility and library interoperability
concerns for such changes.
I'm with others on not liking the idea of adding a new set of "at a
distance" settings into the language. If distributing a package of PHP
code was like distributing a compiled library, then it might make more
sense, but even then we could all end up learning multiple variants of
the same language.
It's interesting that you pick as your example preventing dynamic object
properties. That's definitely a useful option, but it turns out it can
already be done, on a class by class basis. I've put together a quick
library here: https://github.com/IMSoP/php-strict It lets you write this:
class SomeModel {
use \IMSoP\Strict\Properties;
public $someProperty;
}
To me, that seems a lot clearer than this:
namespace Some\Project;
class SomeModel {
public $someProperty;
}
Where "Some\Project" happens to have had a compiler option activated
that injects invisible code to make the class behave more strictly.
If we did want to build such a switch into the language, declaring it
inside the class in a similar way to using a trait would seem pretty
sensible to me.
namespace Symfony\Whatever\Namespace;
function strlen($str) {
return \strlen($str) + 1;
}
// Repeat for a few more namespaces.
This will end up hijacking uses of the strlen() function within the Symfony
codebase due to the way the global namespace fallback works.
Well, as the recent autoloading discussion showed, that global namespace
fallback is not without its problems. And it looks like 7.0 has finally
removed the ability to redefine "true" and "false" as namespace
constants, although I'm not sure if this was just a side-effect of the
phpng work https://3v4l.org/S2AFZ
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php