Hi all. I don't know if this has been discussed before (I've not found it from doing a search), but if it has, please provide me with a link to the discussion.
__autoload() is very convenient, but it has one problem: While classes defined in the __autoload() function (via an include) are accessible globally, any functions being included are not accessible outside the __autoload() function, making them completely inaccessible to the rest of the system. This means that if you have a file containing a class, as well as one or more associated functions, you won't be able to use the functions, if the file containing the class and functions is loaded using autoloading... I've not found a workaround for this (except reintroducing include_once/require_once, which defeats the whole purpose of autoloading...), are others also experiencing problems with this, and if not, do you a) not use any functions, or b) manage some other way? Has there been considerations for solving this in some way? Example: --- email_address.php --- class EmailAddress { public function __construct($address) { ... } // Check if string contains a valid email address .... private $address; } function email_address($address) { return new EmailAddress($address); } --------------------------------- You may then use this like: $address=email_address(<some string expression>); to make the conversion to EmailAddress less "obtrusive" (simulating implicit conversion to user-defined type). However, this doesn't work with autoloading, so you have to either manually include the above file, or use "new" directly: $address=new EmailAddress(<some string expression>); In other words, this function is not a candidate for making it a method. The problem in this particular example would go away if there was a way to implicitly convert from fundamental types to user-defined types, but that's another discussion... Regards, Terje -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php