Jump to content

a group of function should save in a class file or php file?


zgkhoo

Recommended Posts

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.

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 !!!

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');
?>

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.