Re: [PHPTAL] require_once vs autoloading
On Tue, Jun 1, 2010 at 11:10 PM, Tjerk Meesters tjerk.meest...@gmail.comwrote: I could be wrong here, but I think it's not so much any problem with require_once as it is to reduce memory consumption while using the library. This happens when developers only use 30% of the library and yet the whole shebang is loaded on every request ;-) I think I have noticed reduction in memory consumption but not much. For one page I've tested with, it went from 1.58 MB to 1.51 MB (about 4.4%). Have others noticed bigger reduction? ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
On 02-06-2010 at 05:10:07 Tjerk Meesters tjerk.meest...@gmail.com wrote: I could be wrong here, but I think it's not so much any problem with require_once as it is to reduce memory consumption while using the library. This happens when developers only use 30% of the library and yet the whole shebang is loaded on every request ;-) Yes, that's the reason. Large parts of PHPTAL are used only at compile-time. There are optional parts like filters, translation services. There's bunch of Exception subclasses which usually are not used. I'd like all PHPTAL features to just work after you include only PHPTAL.php, but OTOH I don't want to load classes that are not going to be used. Let me know if you find any problems with autoload. -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
On 02-06-2010 at 09:56:23 Robert Goldsmith rgoldsm...@names.co.uk wrote: I think autoloading is a good idea but please keep in mind that the app the phptal is being used within may already have autoloading configured. a prime example would be Zend. I've used spl_autoload_register(). Does it conflict with Zend? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
No idea :) However, if you allowed for autoloading to be optional then if needed people could turn it off and replace it with an external system such as Zend's. Maybe moving the autoloader into its own file and telling people they need to require_once the file if they wish to use the phptal autoloader. Robert On 2 Jun 2010, at 10:25, Kornel Lesiński wrote: On 02-06-2010 at 09:56:23 Robert Goldsmith rgoldsm...@names.co.uk wrote: I think autoloading is a good idea but please keep in mind that the app the phptal is being used within may already have autoloading configured. a prime example would be Zend. I've used spl_autoload_register(). Does it conflict with Zend? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
Hi, Zend uses spl_autoload_register() as well I believe, so that should be safe. The main problem I can see is that if there's an existing __autoload() function, spl_autoload_register() will replace it (as stated in the manual). I don't think putting the autoloader in a separate file will make a difference. This will probably require a change in the major/minor revision number, so that developers are aware that it may break their code. Best, Tjerk On Wed, Jun 2, 2010 at 5:33 PM, Robert Goldsmith rgoldsm...@names.co.uk wrote: No idea :) However, if you allowed for autoloading to be optional then if needed people could turn it off and replace it with an external system such as Zend's. Maybe moving the autoloader into its own file and telling people they need to require_once the file if they wish to use the phptal autoloader. Robert On 2 Jun 2010, at 10:25, Kornel Lesiński wrote: On 02-06-2010 at 09:56:23 Robert Goldsmith rgoldsm...@names.co.uk wrote: I think autoloading is a good idea but please keep in mind that the app the phptal is being used within may already have autoloading configured. a prime example would be Zend. I've used spl_autoload_register(). Does it conflict with Zend? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal -- -- Tjerk ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
On 02-06-2010 at 10:33:00 Robert Goldsmith rgoldsm...@names.co.uk wrote: No idea :) However, if you allowed for autoloading to be optional then if needed people could turn it off and replace it with an external system such as Zend's. Maybe moving the autoloader into its own file and telling people they need to require_once the file if they wish to use the phptal autoloader. Why would someone choose to replace PHPTAL's autoload with something else? (I'm not implying it's perfect or such, just wondering what problem would such option solve). -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
On 02-06-2010 at 10:58:41 Tjerk Meesters tjerk.meest...@gmail.com wrote: Zend uses spl_autoload_register() as well I believe, so that should be safe. The main problem I can see is that if there's an existing __autoload() function, spl_autoload_register() will replace it (as stated in the manual). I don't think putting the autoloader in a separate file will make a difference. This will probably require a change in the major/minor revision number, so that developers are aware that it may break their code. That's a good point. This might avoid the problem in basic case: if (!spl_autoload_functions() function_exists('__autoload')) { spl_autoload_register('__autoload'); } but I'm not sure if it's not too hacky. -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
On 02-06-2010 at 11:10:43 Robert Goldsmith rgoldsm...@names.co.uk wrote: Why would someone choose to replace PHPTAL's autoload with something else? (I'm not implying it's perfect or such, just wondering what problem would such option solve). If people already have autoloader code and wish to use only one autoloader in their application or if they find the autoloader they are already using conflicts with the phptal one then it would be good to allow them to disable the phptal autoloader. require_once PHPTAL.php; spl_autoload_unregister(array('PHPTAL','autoload')); // if needed: spl_autoload_register('__autoload'); Would that be OK? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
I'd have thought that code would do the job assuming it doesn't clobber any previously registered autoloaders. I'd prefer it wrapped up in a little function, however, just for convenience :) By my understanding, you don't need to actually call the autoload method '__autoload' so you could call it something more specific to phptal. Robert On 2 Jun 2010, at 11:29, Kornel Lesiński wrote: On 02-06-2010 at 11:10:43 Robert Goldsmith rgoldsm...@names.co.uk wrote: Why would someone choose to replace PHPTAL's autoload with something else? (I'm not implying it's perfect or such, just wondering what problem would such option solve). If people already have autoloader code and wish to use only one autoloader in their application or if they find the autoloader they are already using conflicts with the phptal one then it would be good to allow them to disable the phptal autoloader. require_once PHPTAL.php; spl_autoload_unregister(array('PHPTAL','autoload')); // if needed: spl_autoload_register('__autoload'); Would that be OK? -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
2010/6/2 Kornel Lesiński kor...@aardvarkmedia.co.uk: On 02-06-2010 at 11:10:43 Robert Goldsmith rgoldsm...@names.co.uk wrote: Why would someone choose to replace PHPTAL's autoload with something else? (I'm not implying it's perfect or such, just wondering what problem would such option solve). If people already have autoloader code and wish to use only one autoloader in their application or if they find the autoloader they are already using conflicts with the phptal one then it would be good to allow them to disable the phptal autoloader. require_once PHPTAL.php; spl_autoload_unregister(array('PHPTAL','autoload')); // if needed: spl_autoload_register('__autoload'); Would that be OK? Wouldn't that cause issues when PHPTAL needs to load more classes during the course of the script's execution? The autoloader stack should not cause any conflicts; if a class can't be found based on the naming conventions of a particular class loader, it will go to the next loader. The argument that one would only want one autoloader is somewhat weak; some other libraries also use their own loaders, so I see no reason to resist that for purity sake. I don't mind to be proven wrong though ;-) The magic required to get around my earlier __autoload() issue should be the only thing that PHPTAL should be concerned about. -- regards, Kornel ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal -- -- Tjerk ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
require_once PHPTAL.php; spl_autoload_unregister(array('PHPTAL','autoload')); // if needed: spl_autoload_register('__autoload'); Would that be OK? Wouldn't that cause issues when PHPTAL needs to load more classes during the course of the script's execution? I think the idea is that this code would go in the host app and could be used to unregister the phptal autoloader as soon as it has been registered as part of the require_once on phptal.php. You would only do this if you already have an autoloader. The autoloader stack should not cause any conflicts; if a class can't be found based on the naming conventions of a particular class loader, it will go to the next loader. That's quite true. If the already-configured autoloader in the host app knows how to handle PHPTAL classes then the phptal autoloader will never actually be called. The argument that one would only want one autoloader is somewhat weak; some other libraries also use their own loaders, so I see no reason to resist that for purity sake. I don't mind to be proven wrong though ;-) It's less for purity and more for complexity and debugging. Having worked in the past in environments where there were multiple autoloaders all doing their little tricks (and, admittedly, before the spl autoloader existed) I can tell you that debugging code can become a very tiresome business and bugs related to the order in which php files are loaded become very hard indeed to track down. One autoloader is a decent tradeoff between resource usage and code readability and predictability. I personally believe 2 or more autoloaders tip the balance away from the latter but with no additional benefit to the former. Robert ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
[PHPTAL] require_once vs autoloading
Kornel, I've noticed this item on phptal.org: Removed all require_once and switched to autoloading. What are the problems with using require_once? Roman ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
Re: [PHPTAL] require_once vs autoloading
I could be wrong here, but I think it's not so much any problem with require_once as it is to reduce memory consumption while using the library. This happens when developers only use 30% of the library and yet the whole shebang is loaded on every request ;-) On Wed, Jun 2, 2010 at 5:20 AM, romtek rom...@gmail.com wrote: Kornel, I've noticed this item on phptal.org: Removed all require_once and switched to autoloading. What are the problems with using require_once? Roman ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal -- -- Tjerk ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal