Re: simple solution to another namespace conundrum?

From: Date: Sat, 21 Jun 2008 20:24:19 +0000
Subject: Re: simple solution to another namespace conundrum?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-38501@lists.php.net to get a copy of this message
Jessie Hernandez wrote: > Hi Greg, > > How is this different from my original proposal > (http://news.php.net/php.internals/34097, > http://news.php.net/php.internals/34097)? > > The patch committed only affects non-namespaced code, your proposal affected all code. In other words, this always works: <?php namespace Foo; include 'blah.php'; use Blah::Closure; $a = new Closure(); ?> whereas this: <?php include 'blah.php'; use Blah::Closure; $a = new Closure(); ?> had the potential to fail with fatal error without code change on upgrade to a newer PHP version that creates the "Closure" class. The committed patch addresses only this shortcoming, and changes nothing else. In other words, this: <?php namespace Foo; $a = new Exception('hi'); var_dump(get_class($a)); ?> still prints "Exception" and not "Foo::Exception". Additionally, unlike your proposal, all existing namespace tests still pass with the behavior change. 2 new tests were added, 1 to test the relaxed behavior, and 1 to test that this next example is a fatal error because definition of Foo::Closure is in the same file as the "use Blah::Closure": <?php namespace Foo; include 'blah.php'; class Closure{} use Blah::Closure; // unqualified name "Closure" is already taken, fatal error. ?> Greg

« previous php.internals (#38501) next »