johnsmith153 Posted July 7, 2010 Share Posted July 7, 2010 If I had a class/function that did a specific thing (check a value and return true or false) yet I only need the function on 10% of pages, would I just include it all the time anyway? e.g: include "usualEssentials.php"; include "specificFunction.php";//function only needed 10% of time ...would there be any benefit of stating it seperatley ONLY when it is needed, or should I just include it in ever page as PHP won't care (and put function in the usualEssentials.php file)? I suppose my question is: does PHP slow down / doesn't like functions being declared on a page if it isn't going to be used. Is this the same for JavaScript? (I have an Ajax function which isn't always needed on every page) Link to comment https://forums.phpfreaks.com/topic/207077-php-include-everything-or-just-what-is-needed/ Share on other sites More sharing options...
ChemicalBliss Posted July 7, 2010 Share Posted July 7, 2010 You would usually either; Use the page to include any "Specific" functions it needs, or Use a class object (Display Object (Ajax) + Controller Object(PHP)?) to determine whether the function is necessary. PHP is a very fast engine anyway so unless your expecting around 200 page views a second with big code bases then this isn't needed. -cb- Link to comment https://forums.phpfreaks.com/topic/207077-php-include-everything-or-just-what-is-needed/#findComment-1082772 Share on other sites More sharing options...
johnsmith153 Posted July 7, 2010 Author Share Posted July 7, 2010 So, just to make it 100% clear: Can I just put all PHP functions in the one includeOnEveryPage.php file regardless of if they are used on that page request? Any idea how this applies to JavaScript? Link to comment https://forums.phpfreaks.com/topic/207077-php-include-everything-or-just-what-is-needed/#findComment-1082778 Share on other sites More sharing options...
ChemicalBliss Posted July 8, 2010 Share Posted July 8, 2010 Can if you want but bad practice. If your just making simple little scripts it really does not matter. If your making production scripts (that you will give/sell) then you need to think about How your script runs. Usually you have some sort of controller (selects which "page" to load depending on the REQUEST variables like GET and POST). In this controller object/function/code you could add a method/function/code that checks what the page needs, or in fact let the page use a function to include the files it needs. I don't really know how to make this any clearer. Good Luck, -cb- Link to comment https://forums.phpfreaks.com/topic/207077-php-include-everything-or-just-what-is-needed/#findComment-1083134 Share on other sites More sharing options...
Mchl Posted July 8, 2010 Share Posted July 8, 2010 Use class autoloading (see __autoload) to only include classes on demand. Link to comment https://forums.phpfreaks.com/topic/207077-php-include-everything-or-just-what-is-needed/#findComment-1083141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.