Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34229 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71271 invoked by uid 1010); 23 Dec 2007 04:14:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 71256 invoked from network); 23 Dec 2007 04:14:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2007 04:14:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=malterisio777@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=malterisio777@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.146.180 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: malterisio777@gmail.com X-Host-Fingerprint: 209.85.146.180 wa-out-1112.google.com Received: from [209.85.146.180] ([209.85.146.180:20876] helo=wa-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D8/D0-64697-9B0ED674 for ; Sat, 22 Dec 2007 23:14:50 -0500 Received: by wa-out-1112.google.com with SMTP id l24so1745801waf.17 for ; Sat, 22 Dec 2007 20:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=qEKpqA/IqORfMo/W0QxPQbUS3cM48+4fUKdXE4FQjJI=; b=JIkMHCHFfYxeTWIlQOifYmrVDD4AiucVkw+1Eg1Hw38oQsrxnAuf1OyUc4YBNYnTYxdCG6abWIbrHwfx9kijU0uwohjM5OYtGpVFr+hGylCOdtAexX4cDxgiwmIgWjy0Gw/+WYhGyeVC+SHVln/2PfKjX6COhPpKXD7bF0hS6u0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=GjDqHw+9+D19ktGKdBmxNPOZbad6Yp3KLf7wwg8UsUnDHyk5jpTICaUPd382SJXZp1DM5zFYn/n8hMX2WswuqFXsqo1tktm/QYaFaIGsyG70ZM2ZfKf0zISO/CnCN1M+eAm5uyFYYp/XKrsbUWHc9vG+Pi48jPfwOoUT1QlbtDM= Received: by 10.142.131.18 with SMTP id e18mr1203435wfd.207.1198383287455; Sat, 22 Dec 2007 20:14:47 -0800 (PST) Received: by 10.142.157.9 with HTTP; Sat, 22 Dec 2007 20:14:47 -0800 (PST) Message-ID: <52dbac0f0712222014t75cef9fcnb96c0dd61b810a6c@mail.gmail.com> Date: Sun, 23 Dec 2007 01:14:47 -0300 To: "Greg Beaver" Cc: "PHP Developers Mailing List" In-Reply-To: <476B3C57.6070102@php.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3906_9501301.1198383287453" References: <52dbac0f0712201536s7fab82a7y2a7111ca5a11711e@mail.gmail.com> <476B3C57.6070102@php.net> Subject: Re: Maybe a problem? undetected name clash makes static method unaccessible through outside static reference From: malterisio777@gmail.com ("Martin Alterisio") ------=_Part_3906_9501301.1198383287453 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2007/12/21, Greg Beaver : > > 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. > > Greg > Sorry, I was busy with something else and forget about this thread for a while. I've tried ::test::foo() but it calls the namespaced function too. I'm trying two approaches to solve this issue: 1) raise an error on function call if the ambiguity is found 2) raise an error on function declaration if the ambiguity is found With (1) the problem I have is: how to provide a way to solve the ambiguity? ie, how can one say if he's referring to the class method or the namespaced function? With (2) one element cannot exist if the other exist. This is a more sensible approach if you're in the "there cannot be two elements which are referred with the same name" way of thinking. But considering that php allows classes and functions to share names... Anyway, the problem with this approach is that the extra checks needed must be done at runtime... Bottom line, if anyone has more ideas... I'll be more than grateful to hear them. Best Regards, Martin Alterisio. ------=_Part_3906_9501301.1198383287453--