DreamerX Posted October 19, 2010 Share Posted October 19, 2010 Hello. If I start building a web project in PHP then how can I reuse some of the code that I have written in other projects later on? Hope I do not need to copy and paste! this is not a good solution for me. Link to comment https://forums.phpfreaks.com/topic/216207-how-can-i-reuse-a-code/ Share on other sites More sharing options...
Bodhi Gump Posted October 19, 2010 Share Posted October 19, 2010 Can you be more specific? Please show us your code. Generally you can reuse functions and classes. Link to comment https://forums.phpfreaks.com/topic/216207-how-can-i-reuse-a-code/#findComment-1123742 Share on other sites More sharing options...
DreamerX Posted October 19, 2010 Author Share Posted October 19, 2010 For example, if I want to make a header an footer that I can use for all my pages! Link to comment https://forums.phpfreaks.com/topic/216207-how-can-i-reuse-a-code/#findComment-1123757 Share on other sites More sharing options...
trq Posted October 19, 2010 Share Posted October 19, 2010 For something as simple as header and footer templates, just use include to include the files where there needed. For reusable code, your need to learn good application design practices. it's not exactly something that can be easily explained within a simple forum reply. Link to comment https://forums.phpfreaks.com/topic/216207-how-can-i-reuse-a-code/#findComment-1123777 Share on other sites More sharing options...
Bodhi Gump Posted October 19, 2010 Share Posted October 19, 2010 And if you want to be absolutely sure that your code is used, but never more than once at a time, use include_once(). Link to comment https://forums.phpfreaks.com/topic/216207-how-can-i-reuse-a-code/#findComment-1123969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.