Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50911 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62154 invoked from network); 8 Dec 2010 12:05:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Dec 2010 12:05:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=reinier.van.loon@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=reinier.van.loon@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.174 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: reinier.van.loon@gmail.com X-Host-Fingerprint: 209.85.214.174 mail-iw0-f174.google.com Received: from [209.85.214.174] ([209.85.214.174:60407] helo=mail-iw0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/66-02061-5747FFC4 for ; Wed, 08 Dec 2010 07:05:09 -0500 Received: by iwn9 with SMTP id 9so1622746iwn.33 for ; Wed, 08 Dec 2010 04:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=YWjZzK5aabIwbZh+xJxi5IA08mRdlZ1TsJ6yupu/3g4=; b=AxAp/IiurvjNZni4pw1cvTDqGOs3nYELR0Zj0fadHiPClFGZlKyCdCU/63FCuamejC M0VMHWtbyX9ooq9+pgFiRJzBsnolyTCeXF6T+YMF+H+sSR56CI4a/yDyc25PnET+WI2D LJdUkgEopWFAIeP1fW8KPEH2H41quhLzhazls= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=QF8waGX3jI37GLNHOgwMsUG2aphHu4oTL37FBnZ0cd3gaX5pjlCMSLcGWOvUQDazjw VDenq4hWu6ApE9yYVp+xDpLdV4YJHMK1kYeYYr6kCqbA0A/ZCXqOoiahMg8iE4RZPXxz yilkB9Um0nIdtSWWxk0tRlwFTlGoSApHxgEIQ= MIME-Version: 1.0 Received: by 10.231.39.205 with SMTP id h13mr9125998ibe.148.1291809905563; Wed, 08 Dec 2010 04:05:05 -0800 (PST) Received: by 10.231.153.196 with HTTP; Wed, 8 Dec 2010 04:05:05 -0800 (PST) In-Reply-To: References: Date: Wed, 8 Dec 2010 13:05:05 +0100 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: RFC __autodefine / spl_autodefine From: reinier.van.loon@gmail.com ("Loon, Reinier van") > __autoload() works fine if you have exactly one implementation for your entire > system with exactly one set of logic for how to map a class name to a file > name. As soon as you try to mix two different libraries together, fatal > error. > > spl_autoload() does not suffer from this short-sighted problem but > accomplishes the same goal in a much more robust fashion. > > Any new meta-auto-load mechanism should forego the dead-end that is a single > unique __auto*() function and just use a design that actually works, aka > spl_autoload() or similar. I see the problem. At projectpier.org we have the one code set situation. Given the reactions, I will rewrite the RFC to use spl* functions with the information supplied above. > With that said, I like the idea of generalizing autoload to include functions > et al. Autoloading functions would make my life a lot easier. :-) Yes, the alternative solution is to write a wrapper function: somefunc($a, $b) becomes ppcall("somefunc", $a, $b) Works but if we can get this in PHP itself it will be much better. >To be fair, though, half of the potential benefits the OP listed are already solved > by using a version control system. Any version control system. If you're > still having collisions at the file level when two people work on the same > file it's because you're an idiot and are not using version control (or the > changes touch each other, in which case this proposal wouldn't help you > anyway). I disagree (but otoh, I am an idiot :-)). I just think there is no conceptual need to group functions into a file. I also don't believe in distributed vcs (probably idiotic again :-)). The problem of integrating code is simply postponed with a dvcs. At work we have good experiences with a centralized code repository where people can work together, where backups are taken care of and were revision history is built in. Integration issue are solved before the code is touched. Also, I think it is crazy I have to do a grep on a filesystem to find out in which file a function is defined (e.g. grep -i -l "ion pick_date_widget"). I know, documentation etc. But that argument only works when a system is in good shape when you take over. Why can't I just see by the file name what definition hides inside? > The main advantage of this proposal would be lazy-loading of functions. > I don't think autoloading methods makes any sense since classes cannot be split between files anyway. I think I was not clear with my remark on __call and __callStatic. I think autodefining of methods is already possible by using __call and __callStatic for that. The __call is used in this example for dynamically adding methods to a class: http://www.php.net/manual/en/function.call-user-func.php#89636. The same __call function can be used to dynamically add code to the class. But I think it would be better if the run time would do this in a uniform way via autodefine. The minimal definition in my view for a class would be "class SomeClass {}" or "class SomeClass;" . But then classes resemble namespaces to much (but in my view a class can also be viewed as a namespace for a set of variables and functions). This is however getting to theoretical, so lets keep it simple and let's assume that the minimal definition of a class should have its variables, like this "class SomeClass { var a; var b; }" and that methods can be added dynamically. > I'm not entirely sure what else is actually reasonable to autoload. Classes, > Interfaces, Functions, and Traits make up the scope of first-class code > structures, don't they? Autoloading a variable doesn't even make sense to me, > and include files are already handled by include[_once]. Autodefining variables does make sense. Suppose you have a variable called "$language" which is an array with a lot of language items and that you have put this array somewhere. Current practices forces you think what the possible paths are how the variable is accessed and then include this array at the proper places. So far so good. But things change in time and code is added to the system and suddenly the variable is referenced via a path which was not foreseen. Current practice forces you to rethink the include locations. But what happens in reality? Most people simply include all the files somewhere upfront, just to be sure. Again a lot of code parsed and processed which may not be executed. Wouldn't it be much more elegant to define the variable when it is first referenced? Of course, this could be emulated with a function that would be autodefined, so that is why I chose the minimal solution to not have variables autodefined. But another interesting option for autodefining variables is that you are able to track which variables are used in your application. The fun thing is that you can do this in every environment. For development it is interesting to see if you are using variables which you don't recognize (typo's) or don't want to use (e.g. $HTTP_POST_VARS), for testing it is interesting to see if your test cases are using the most important variables and for production it is interesting to see which variables are used at all and which never. The paragraph above applies of course to all objects that can be autodefined. As pointed out in the RFC, autodefine enables you to get more insight and thus more control over your codebase. The include and include_once are simply mentioned because they are already identified by the parser. And there is a difference between the two. Maybe you want to know that an include_once is called multiple times to rethink the location of the include. Thanks for all the feedback so far. It is much easier for me to react to arguments and remarks then to come up with answers / ideas when writing an RFC. Cheers, Reinier