Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66704 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96633 invoked from network); 19 Mar 2013 16:36:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2013 16:36:42 -0000 Authentication-Results: pb1.pair.com header.from=dnl.rlnd@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dnl.rlnd@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.50 as permitted sender) X-PHP-List-Original-Sender: dnl.rlnd@gmail.com X-Host-Fingerprint: 209.85.214.50 mail-bk0-f50.google.com Received: from [209.85.214.50] ([209.85.214.50:42847] helo=mail-bk0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/96-58539-81498415 for ; Tue, 19 Mar 2013 11:36:40 -0500 Received: by mail-bk0-f50.google.com with SMTP id jg9so324853bkc.23 for ; Tue, 19 Mar 2013 09:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=r0PkoY8p2sghfrhJ/xz8VnQ2FMlhaJxRu9XlQPYGpz0=; b=zpUhBBgbR2XGX8gcAGs78DaFwHEYdxxvBPkdvt01D83QQXTqflRWi/5wSgXgRvaKIv GpqcOIEajN9S33PRB1gKwMf3syLKtdxUhuNe8fYGT8w4vk7FWrRoVdGLiwfMX3+68gi0 0vhUC716NwqX5sKczh/JSL6JYZI/Fgf/TsFPsltdSy7NBBeGtPY3HUukI6Y4yiELHLqC cLGyHUIJo5BF2qFnGjiAwJZexThc/mC7kwyk325V3YBJkpXLWXEtH8dmb0a0JnMNdX1f ekaXsDgSgWFDUwm76EsxtJlfKKh8v9aAxUAKvnNFgcFmwweMbD3T0JrmFo2eYShLxrCT yYqw== X-Received: by 10.204.108.198 with SMTP id g6mr9146642bkp.19.1363710996752; Tue, 19 Mar 2013 09:36:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.10.144 with HTTP; Tue, 19 Mar 2013 09:35:55 -0700 (PDT) In-Reply-To: References: <20.05.17382.B0318415@pb1.pair.com> <4F.50.28284.AA918415@pb1.pair.com> Date: Tue, 19 Mar 2013 17:35:55 +0100 Message-ID: To: PHP Development Cc: Pierre du Plessis , Bruno CHALOPIN , =?UTF-8?Q?Mat=C4=ABss_Roberts_Treinis?= Content-Type: multipart/alternative; boundary=089e0122ed7489e65904d849b50c Subject: Re: [PHP-DEV] __invokeStatic() method From: dnl.rlnd@gmail.com (Daniele Orlando) --089e0122ed7489e65904d849b50c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable It is clear to me that there are valid reasons to say yes to this proposal, but there are a lot to say no too. Even if it could be interesting in theory, due to of how PHP handles collisions between classes and functions names (no check at all), implementing a callable class could break existing code. At the moment a class and a function with the same name can coexist, but implementing a callable class would mess this state of affairs. With the adoption of the namespaces, I think that this collisions could became so rare to not exist, but of course we cannot ignore pre existing situations. As suggested by Patrick Schaaf, a workaround is to implement a function, with the same name of the class, that behaves like a wrapper for a method call. It is a good point, but has the negative side that it must be implemented for every class who follow this pattern. It is not usable in a framework for example. It seams that to handle consistently a callable class is to modify PHP to treat functions/classes names case sensitive and to trigger an E_WARNING (or similar) in case of collision. In this way new code could take advantage of the new syntax and old code could simply suppress the warning. What do you think? 2013/3/19 Mat=C4=ABss Roberts Treinis > Bruno, > > Poor or questionable design or language use is not what this discussion i= s > about. PHP's greatest strength is its flexibility - PHP does allow to do > silly and sometimes, questionable things. Trying to limit this flexibilit= y > is like trying to limit PHP, which is obviously bad thing to do. Example > given by Pierre clearly shows possibility of such code, and in fact, I ha= ve > seen such code myself in some applications where methods are shorthand's = to > specific functionality provided as the class with same name. I even appro= ve > such use and believe it can be quite handy for utility functions which do= es > some specific task and where you do not want your function to be miles > long, so you split it to handful of methods and wrap them in class. > > These proposed changes can potentially break a lot of peoples work withou= t > a real profit to the language or its users. By my opinion, syntax > considering function and object calls should stay separated to ensure cle= an > and convenient way to properly identify one from another. Also, there are > no or never has been clear and unified standard by PHP for how to name > things in PHP. If one chooses to name his functions with names similar or > exactly like classes, he must be able to do so. > > 2013/3/19 Pierre du Plessis > > > > Le Tue, 19 Mar 2013 09:37:43 +0200, Pierre du Plessis a =C3=A9crit : > > > > It would break existing software if you have a class and function > with > > > > the same name. > > > > Consider the following example: > > > > > > > > class foo { > > > > } > > > > > > > > function foo() > > > > { > > > > > > > > } > > > > > > > > Now what if you have several calls to foo() in your existing > > > > application? With the new change, will those calls call the functio= n, > > or > > > > invoke the __invokeStatic method if it is available? > > > > > > It will clearly technically lead to a problem. Now I don't see why in > the > > > world a class and a function could share the same name. Regarding > > > conventions, a class name should begin with an uppercase character an= d > a > > > function a lowercase one. I don't see any relevant use case where a > class > > > and a function should share the same name. > > > > > > > > PHP doesn't care about uppercase or lowercase when it comes to function > > names. > > Have a look at http://3v4l.org/cePT5 for an example. > > And not everybody uses conventions anyway (although they should) > > > > Although it is not common to have a class and function have the same > name, > > it can happen. > > Take the following code as an example. > > > > class Debug { > > public static dump($var) > > { > > // some code to debug $var > > } > > } > > > > function debug($var) > > { > > return Debug::dump($var); > > } > > > > The problem is clear if you have a __invokeStatic method in the debug > > class, and you want to make a call to debug(). > > > --089e0122ed7489e65904d849b50c--