zgkhoo Posted November 29, 2007 Share Posted November 29, 2007 i have complete write a group of functions.. a group of function should save in a class file or php file? and how to integrate into several pages? use include or require keyword? thanks Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 29, 2007 Share Posted November 29, 2007 If something is required... require() it... include otherwise. That's what I do xD And you don't just make a bunch of functions, cram them into a class and call it a day's work... doesn't work like that. Just require 'em and you'll be fine... you'd have to rewrite your functions (I think)and grasp the concepts of OOP (which I do not so don't listen to me) etc. if you wanted to use classes. I tend to stray away from classes they just seem to make things harder... better to learn all the basics and get some experience behind you before you venture towards OOP I think. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 29, 2007 Share Posted November 29, 2007 You can create separate class for related functions and can include wherever you require :: for e.g. I have user_info.class.php which contains functions like class User_info { function check_auth() function login($user, $pass) function user_info_data() function user_option() function logout() } And wherever I want this class I use this require_once("user_info.class.php"); P.S : other may have different ideas... so wait !!! Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted November 29, 2007 Author Share Posted November 29, 2007 how about write all function and save in an functions.php file and include using include '../../functions.php'; ??? Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 29, 2007 Share Posted November 29, 2007 That'll work... If it helps, something I'm working on looks a bit like this... <?php session_start(); // Some variables here $some_var = a; $b = 3; // Config file with constants and checking to see if the system is offline etc. require('/path/to/file/config.php'); // Init file has my classes, instantiates them etc. require('/path/to/file/init.php'); // Header template file... include('/path/to/file/header.php'); // HTML here... // Footer template.. include('/path/to/file/footer.php'); ?> Quote Link to comment Share on other sites More sharing options...
aschk Posted November 29, 2007 Share Posted November 29, 2007 If they're functions that relate to an "object" then yes they should probably be in a class of their own. Or even if they are related in some form or another you can still class them, just make them static. As for the require vs include : they behave differently with regards to errors. I'll leave that for you to investiage Quote Link to comment 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.