GHW_Chronic Posted July 5, 2006 Share Posted July 5, 2006 If I do this:[quote]function OMFG($id){ return $id + 1;}[/quote]and I don't use the OMFG function, will the php script still load the function?See, I have 2 very large functions that I don't want to be loaded if the page is not using them because it would delay the page on load. Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/ Share on other sites More sharing options...
wildteen88 Posted July 5, 2006 Share Posted July 5, 2006 PHP will load the function, but it wont run the function untill it you tell it to. Also the two functions shouldn't cause any problems with the page load times. Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/#findComment-53514 Share on other sites More sharing options...
GHW_Chronic Posted July 5, 2006 Author Share Posted July 5, 2006 the functions are 1000 lines total together. So PHP will read none of these lines unless one of the functions is used? Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/#findComment-53516 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 Put the functions into separate files and use the include function when you write scripts that call them. If you don't include them, then your scripts won't have the overhead.Ken Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/#findComment-53519 Share on other sites More sharing options...
Buyocat Posted July 5, 2006 Share Posted July 5, 2006 Surely you can break these functions up into smaller single action functions? Any single function that is 1000 lines has gone beyond the scope of a function. It sounds like you should be creating a class with methods in this case. Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/#findComment-53527 Share on other sites More sharing options...
GHW_Chronic Posted July 5, 2006 Author Share Posted July 5, 2006 The functions are for 2 things. 1: pawn highlighting (smaller function) 2: amxmod to amxmodx auto-converter (which unless you know what pawn, amx, and amxx are, you don't know what I'm talking about). And the length of these functions is minimal.And I'm just going to have to seperate these functions from the other functions in the include file. I didn't want to have to do this, but I guess I will if PHP is going to want to read these functions everytime the page loads. Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/#findComment-53529 Share on other sites More sharing options...
Buyocat Posted July 5, 2006 Share Posted July 5, 2006 If there is no way to break them up then why not just add an if case at the top of the page you want to use them on, but only sometimes, and not include the file on condition A.So,[code]if (!isset($_POST['user_request'])){// just diplay the page with a form or something} else {include('a_really_big_function.php');include('another_rbf.php');// use them now, they were only loaded when needed// print stuff out for the user}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/#findComment-53553 Share on other sites More sharing options...
GHW_Chronic Posted July 5, 2006 Author Share Posted July 5, 2006 again you missed the point. I ALWAYS want to include the first 4 functions in an included file. I only want the last 2 functions if they are used in a page. They are all in the same file. But I will just force myself to seperate the files into amxx_functions.php and amxx2_funcstions.php.[End Topic] Quote Link to comment https://forums.phpfreaks.com/topic/13771-functions/#findComment-53554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.