Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34198 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48010 invoked by uid 1010); 21 Dec 2007 10:08:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 47995 invoked from network); 21 Dec 2007 10:08:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Dec 2007 10:08:40 -0000 Authentication-Results: pb1.pair.com header.from=jochem@iamjochem.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jochem@iamjochem.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain iamjochem.com from 194.109.193.121 cause and error) X-PHP-List-Original-Sender: jochem@iamjochem.com X-Host-Fingerprint: 194.109.193.121 mx1.moulin.nl Linux 2.6 Received: from [194.109.193.121] ([194.109.193.121:55386] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/00-46708-6A09B674 for ; Fri, 21 Dec 2007 05:08:39 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id B2B3124C889; Fri, 21 Dec 2007 11:08:34 +0100 (CET) X-Virus-Scanned: amavisd-new at moulin.nl Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (mx1.moulin.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U2sKKHDdTAvr; Fri, 21 Dec 2007 11:08:31 +0100 (CET) Received: from [192.168.1.10] (bspr.xs4all.nl [194.109.161.228]) by mx1.moulin.nl (Postfix) with ESMTP id DD5CA24C76E; Fri, 21 Dec 2007 11:08:30 +0100 (CET) Message-ID: <476B909F.9070903@iamjochem.com> Date: Fri, 21 Dec 2007 11:08:31 +0100 User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Greg Beaver CC: Martin Alterisio , PHP Developers Mailing List References: <52dbac0f0712201536s7fab82a7y2a7111ca5a11711e@mail.gmail.com> <476B3C57.6070102@php.net> In-Reply-To: <476B3C57.6070102@php.net> X-Enigmail-Version: 0.95.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Maybe a problem? undetected name clash makes static method unaccessible through outside static reference From: jochem@iamjochem.com (Jochem Maas) Greg Beaver schreef: > Martin Alterisio wrote: >> Consider the following code: >> >> foo.php: >> > class test { >> public static function foo() { echo "I'm foo in class test\n"; } >> public static function foo2() { self::foo(); } >> } >> ?> >> >> foo2.php: >> > namespace test; >> function foo() { echo "I'm foo in namespace test\n"; } >> ?> >> >> test.php: >> > include 'foo.php'; >> include 'foo2.php'; >> test::foo(); // I'm foo in namespace test >> use test::foo as dummy; >> test::foo(); // I'm foo in namespace test >> test::foo2(); // I'm foo in class test >> $test = 'test'; >> $test::foo(); // I'm foo in class test >> call_user_func(array('test', 'foo')); // I'm foo in class test >> ?> >> >> Please review the following observations: >> >> There's a name clash that goes undetected: test::foo refers to both a >> namespaced function and a static method. >> >> Once the clash occur there's no way to refer to the static method through a >> static reference, except when within the class scope where you can refer to >> the method through self:: >> The static method remains partially hidden by the namespaced function. > > Don't forget about ::test::foo() which refers to class test, method > foo(). However, this is an issue, and one of the main reasons I dislike > putting functions and constants in namespaces, as this ends up sort of > like OO without inheritance and confuses the issue of static methods as > you pointed out. > > However, having said that, in my experience, developers either use > functions or OO, very rarely mixing the two on an extensive basis, and > so name collisions become much less likely between static methods and > namespaced functions. why exactly should we need to have this ambiguity and possible naming collision? I thought namespaces are about avoiding naming collisions? > > Greg >