I have some functions I use in all of my pages.
now these functions are hang loose in a file that I include to every page and then call them.
I want to put all these functions in utility class, but then I'll have to create an instance of
this class on every page.
is the efficiency will be much worse ( or better? ) does it takes a lot of memory?
cause it is much nicer and cleaner to put everything in classes.
open for all pros and cons
Thanks
Guy
loose function or class in terms of memory and efficiency
Moderator: General Moderators
if there's no need to access member variables then there's no need for an instanceOn the other hand a class only with static methods isn't that usefull 
Code: Select all
<?php
class CTest
{
function doIt()
{
echo 'function CTest::doIt()';
}
}
CTest::doIt();
?>I'm not sure I understand
I don't need any members.
most of my functions are displaying functions or socket handling functions.
I'd like to put them all in a classes Utils,display,sockets and call them
like: Utils::PrintPage($arr)
my fear is that it will fill the memory and will be less efficient.
is there a way to check it ?
let's say I want all three classes like this display, utils and sockets,
does it matter??
or is the changes are small that it doesn't matter
Thanks
Guy
most of my functions are displaying functions or socket handling functions.
I'd like to put them all in a classes Utils,display,sockets and call them
like: Utils::PrintPage($arr)
my fear is that it will fill the memory and will be less efficient.
is there a way to check it ?
let's say I want all three classes like this display, utils and sockets,
does it matter??
or is the changes are small that it doesn't matter
Thanks
Guy
I'm not an expert but I always avoid classes unless I really have to have one.
Also, I try and avoid includes - as far as practicable.
I did a speed test once with a single file that contained 1500 lines of code in various functions, comparing it with an almost empty file which included just one function from the big, 1500 line file. The include took a few hundredths of a second but the whole 1500 line file only took a few thousandths of a second - might even have been a few tens of thousandths.
So, for best speed, it would be nice to have something like the Dreamweaver library which would let you have a single source for a function's code which is then automatically updated to as many files as you need to use it in - thus avoiding the need to include common functions.
The speed gains are of the order of hundredths of a second (as tested on my desktop) so it's not a big deal. Maybe if you had dozens of includes it would be time for a rethink.
Also, I guess there's a memory hit from 1500 lines of functions.. Haven't quite worked out yet which is more important speed or memory - or some happy medium. I guess if you are counting visits to your site per day/week memory isn't an issue; but if you get hundreds of visits per hour or minute you might be more concerned.
Also, I try and avoid includes - as far as practicable.
I did a speed test once with a single file that contained 1500 lines of code in various functions, comparing it with an almost empty file which included just one function from the big, 1500 line file. The include took a few hundredths of a second but the whole 1500 line file only took a few thousandths of a second - might even have been a few tens of thousandths.
So, for best speed, it would be nice to have something like the Dreamweaver library which would let you have a single source for a function's code which is then automatically updated to as many files as you need to use it in - thus avoiding the need to include common functions.
The speed gains are of the order of hundredths of a second (as tested on my desktop) so it's not a big deal. Maybe if you had dozens of includes it would be time for a rethink.
Also, I guess there's a memory hit from 1500 lines of functions.. Haven't quite worked out yet which is more important speed or memory - or some happy medium. I guess if you are counting visits to your site per day/week memory isn't an issue; but if you get hundreds of visits per hour or minute you might be more concerned.