Hi,

Unfortunately there may be a problem with this path and namespaces in 5.3. I 
tried to warn about this while namespaces were being implemented, but everyone 
was in the "autoload will always be for classes only".

Right now when you use fully qualified name of a class when inside a namespace, 
you need to always prefix it with backslash: \Foo. 

For functions, it was deemed too hard as most internal functions remain in 
global space, so inside a namespace one would need to prefix every call with a 
backslash. If you don't prefix with backslash, the interpreter will try both 
options at runtime: if there's a local function, it'll run, if there isn't, 
it'll try to find it in global space, and only if it's not there, it'll fail.

The only reason this double lookup works is because there's no autoload for 
functions, and it's the reasons why classes don't have this feature. There was 
a big discussion back about how to enable them both without severe performance 
penalty or unintuitive behavior, but none was found. 

I am myself a big proponent of autoload for functions, as there was never a 
good reason for excluding them from autoload (except for the artificially 
introduced one in 5.3).

Regards, 
Stan Vassilev 
  ----- Original Message ----- 
  From: Rack-Soft security 
  To: internals@lists.php.net 
  Sent: Friday, October 16, 2009 5:32 PM
  Subject: [PHP-DEV] Autofunc patch (automatically loading functions like 
autoload)


  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



------------------------------------------------------------------------------


  -- 
  PHP Internals - PHP Runtime Development Mailing List
  To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to