Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45838 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82702 invoked from network); 17 Oct 2009 18:10:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2009 18:10:30 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 69.5.8.4 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 69.5.8.4 hc02.futurequest.net Linux 2.4/2.6 Received: from [69.5.8.4] ([69.5.8.4:43479] helo=hc02.futurequest.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/06-11886-4980ADA4 for ; Sat, 17 Oct 2009 14:10:30 -0400 Received: (qmail 29202 invoked from network); 17 Oct 2009 18:10:24 -0000 X-Originating-IP: [98.212.48.71] To: internals@lists.php.net Date: Sat, 17 Oct 2009 13:10:22 -0500 User-Agent: KMail/1.11.2 (Linux/2.6.27-14-generic; KDE/4.2.2; i686; ; ) References: <20091016143251.e95b77e5@mailro.4psa.com> In-Reply-To: <20091016143251.e95b77e5@mailro.4psa.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200910171310.22916.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Autofunc patch (automatically loading functions like autoload) From: larry@garfieldtech.com (Larry Garfield) On Friday 16 October 2009 9:32:51 am Rack-Soft security wrote: > Hello, > > I am submitting quite an interesting patch to PHP 5.2.11 and PHP 5.3.0. It > is used in production on hundreds of machines without any issues. > > Basically the patch adds the autofunc function that performs quite in the > same way like autofunc, only that it does it for functions. As do you know, > if PHP can not find a function it will issue a fatal error. With autofunc > you can find the function somewhere and load it. Management of large no OOP > projects (or mixed OOP/procedural) is much easier with this. I know that > there are workarounds for loading functions, like adding them static to > classes, but this is not efficient and involves important changes to code. > > I have attached some PHP files to test with, you must execute index.php > that will load autofunc when the loaded functions can not be found. > > Let me know if you have any questions regarding the patch. > > Best regards, > Bogdan Looking at the sample code in autofunctest.tar.gz: - Why are you using __autofunc()? As far as I'm aware the recommendation for classes these days is to never use __autoload() but spl_autoload_register(), since you can then stack autoloaders rather than running the risk of a duplicate function name collision. I would recommend skipping the magic function entirely and going straight to a stackable approach a la spl_autoload*(). To wit: func_autoload_register('myloadfunction'); func_autoload_unregister('myoldloadfunction'); func_autoload_functions(); func_autoload_call(); See: http://us2.php.net/manual/en/ref.spl.php - I get the $VN_function global variable, as that's your lookup table. Naturally a production implementation would do something more robust, but it's good for example purposes here. I do not, however, understand what's going on with $VN_global. I just see an eval() and run in terror. What's that all about? Are you autoloading global variables too? I don't understand. - How would this handle namespaces? Functions can have namespaces just like classes can, so autoloading functions should handle namespaces too, in much the same way as classes. -- Larry Garfield larry@garfieldtech.com