Lee, On Fri, Mar 6, 2015 at 7:06 AM, Lee Davis <leedavi...@gmail.com> wrote: > > Hi Anthony. > > This issue that has plagued me in the past, specifically with the use of > traits: > > Error: http://3v4l.org/VFguK > OK: http://3v4l.org/73b86 > > Although when combined with opcache does causes very confusing behaviour, I > do worry that removing the error altogether may make it worse for > developers. > > Take this example with constants: > > namespace Biz { > const Bar = 41; > } > > namespace Foo { > const Bar = 42; > } > > namespace Foo { > use const Biz\Bar; > echo Bar; > } > > // Fatal error: Cannot use const Biz\Bar as Bar because the name is already > in use > > http://3v4l.org/0pRZk > > An error here is far more useful that trying to exhibit the behaviour of > when the namespaces are declared in reverse order: > > namespace Biz { > const Bar = 41; > } > > namespace Foo { > use const Biz\Bar; > echo Bar; > } > > namespace Foo { > const Bar = 42; > } > > // 41 > > http://3v4l.org/E4PFX > > I suppose the question here is; Does the declaration order matter? > Personally I think it should.
If we were just talking about a single file, yes. However, we're also talking about file include order. <?php //a.php namespace Foo; class Test {} <?php //b.php namespace Foo; use Bar\Test; function foo() { var_dump(new Test); } If we include `b.php` first, then the code will always work (even after we include a.php). It will always reference Bar\Test as well (including a.php doesn't change anything). Today, if you turn on opcache, you can include them in any order and the behavior will always work correctly. If you turn off opcache however, including a.php before b.php will cause an error that the use line Bar\Test clashes with Foo\Test. The point that I'm asserting is that the error is useless since it's neither robust nor indicating a potential issue. Classes are 100% determined at compile time, without a symbol table lookup and without any fallbacks. So the error is superfluous. In fact, it's even worse because with an extensible system, a 3PD developer could write a class, and include it which would cause your code to compile error. https://www.drupal.org/node/2446259 Therefore I'm suggesting to remove the error. Anthony -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php