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
[email protected]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php