- Joined
- Jul 4, 2004
- Messages
- 211
- Reaction score
- 0
I have been looking into this a bit, and wanted to ask a question about it... Is coding PHP in OOP worth it? For instance, I am not seeing how:
is any better than doing:
Now, I have heard the advantage comes with not having to repeat, however, if you just make files containing the needed functions with correct arguments and such you are not / should not be repeating much if any unneeded code. So I am wondering, is it worth it to have to do class and all that? I keep hearing it is, yet I see no real advantage to doing it (Benchmarks show it to be slower, from what I can tell) compared to what I am doing currently (Making files filled with functions and just including them).
PHP:
<?php
// The following class is in Something.php
class Something {
function add($a,$b) {
return $a+$b;
}
}
// Now in index.php
include("Something.php");
$add = new Something;
echo $add->add(1,5);
?>
is any better than doing:
PHP:
<?php
// The following function is in Something.php
function add($a,$b) {
return $a+$b;
}
// The following is in index.php
include("Something.php");
echo $add($a,$b);
Now, I have heard the advantage comes with not having to repeat, however, if you just make files containing the needed functions with correct arguments and such you are not / should not be repeating much if any unneeded code. So I am wondering, is it worth it to have to do class and all that? I keep hearing it is, yet I see no real advantage to doing it (Benchmarks show it to be slower, from what I can tell) compared to what I am doing currently (Making files filled with functions and just including them).


