Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36817 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64642 invoked from network); 6 Apr 2008 03:08:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Apr 2008 03:08:17 -0000 X-Host-Fingerprint: 74.161.252.233 adsl-161-252-233.mia.bellsouth.net Received: from [74.161.252.233] ([74.161.252.233:14325] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A3/34-41902-E9E38F74 for ; Sat, 05 Apr 2008 22:08:15 -0500 To: internals@lists.php.net,Julian Reich Message-ID: <47F83E9B.1060700@gmail.com> Date: Sat, 05 Apr 2008 23:08:11 -0400 User-Agent: Thunderbird 1.5.0.12 (X11/20070530) MIME-Version: 1.0 References: <5D0C3386-C2BC-4086-87BB-806E2350B373@eenterphace.org> In-Reply-To: <5D0C3386-C2BC-4086-87BB-806E2350B373@eenterphace.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 74.161.252.233 Subject: Re: namespace implementation (irritating warning and autoload) From: jrhernandez05@gmail.com (Jessie Hernandez) Julian, Regarding the name resolution rules, I posted a patch a few months ago with what I think is a more reasonable lookup order (http://news.php.net/php.internals/34097), but did not get much feedback. Would you like to try it out? (let me know if it doesn't apply cleanly against the current PHP_5_3) Regards, Jessie Hernandez Zend Certified Engineer (http://zend.com/zce.php?c=ZEND006359&r=222727282) Julian Reich wrote: > Hi, > > I recently started porting an application to PHP 5.3. > > 1. While testing the new namespace implementation I noticed the following: > > namespace Test1; > function fooBar() { echo 'Test1::fooBar()' . PHP_EOL; } > > namespace Test2; > use Test1; > Test1::fooBar(); > > Executing the code above results in a warning: "The use statement with > non-compound name 'Test1' has no effect in [...]". > I understand the rationale behind this warning but it simply isn't true: > omitting the use statement results in a fatal error: "Class > 'Test2::Test1' not found in [...]". > > Since the following code executes without warning or error I think the > code above (without use statement) should also execute just fine. > > namespace Test1::Test2; > function fooBar() { echo 'Test1::Test2::fooBar()' . PHP_EOL; } > > namespace Test3; > Test1::Test2::fooBar(); > > But I'm not quite sure about the warning (about the non-compound use > statement): I think the warning should either be dropped or its > statement should be fulfilled. > > > 2. I'm sorry for bringing this up again: The current name resolution > order makes using the namespace feature in conjunction with autoloading > less usable and somewhat error prone. > > a. To avoid that internal classes introduced to PHP somewhen in the > future break my app I've to add a number of use statements that would > not be necessary otherwise. > So to be on the safe side one has to > i. "use" all classes from the current namespace which is > annoying and especially in bigger projects one might easily forget to > "use" classes when making changes > ii. use exactly one file per namespace (this might work well > especially with few classes per namespace that are mostly used together, > but one can easily think of a lot of situations you want > to load just the classes that are really needed and in the end this is > what autoload is for) > iii. avoid the usage of autoload > > b. Applications might behave differently when packaged > i. one class per file using autoload (without "use"-ing > classes from the current namespace) > ii. all classes in one file > > c. Implementors of autoloaders can keep the performance hit to a > minimum using some kind of caching. > > I think the current resolution order is a WTF-factor especially for > unexperienced users or users coming from other languages. > > I know that the above arguments might have been already on this list but > I couldn't find some definitive decision to keep the current name > resolution order. If I've missed that I'm sorry for the noise. > > > Regards, > Julian Reich