[go-on-soapbox]
this whole discussion is pretty far off-topic, but let me put in my 2c anyway:
in and on itself, there is nothing in oop that should cause it to be low performance.
the remark about embedded system using c rather that cpp is mostly correct, but is not really relevant here: the same embedded systems that shy away from c++ usually dont use dynamic memory allocation at all. with languages such as php, there is ONLY dynamic memory allocation, and quite a lot of it.
it is true that php 4 had a slight deficiency that could cause problems to oo code.
i will elaborate a little:
with php, by default, parameters are passed to functions by value, and not by reference.
this means that if you pass a large array to a function, and you dont explicitely specify "by reference" (in php that means use "&" in front of the parameter in the function declaration), the whole array will be copied each time you call the function.
in reality, "objects" in php are a little more than glorified ("blessed" if you talke perlese) associative arrays. if you use objects extensicvely, AND you pass them as parameters to functions, AND you dont do it "by reference", you may pay a performance penalty. no more so than if you pass similar sized associative arrays, but also no less.
php 5 changed that: object variables always hold a refernce to the object rather than the object itself, so there is no penalty for passing them to functions as parameters.
the notion that objects are expensive in terms of memory management regardless of function calls is just not true in php. creating and destroying an object doesnt cost more in cpu and memory than creating and destroying (you rarely explicitly "destroy" anything in php. things get destroyed when they go out of scope) similar sized associative arrays.
to summarize:
using oo in php 4 can cause a performance penalty IF you pass object as parameters to functions, AND IF you dont use "pass by reference" ("&") for those functions.
there is no such penalty for php 5, and the php 4 penalty can be negated by using reference parameter passing for the objects (and for other large structures).
of course, it is always possible to create a screwed up "benchmark" that will show a huge penalty, as in the example cited above. but if the example would add a
$b = array(1, 2, 3); line, you would see a very similar effect as the call to
new thing();
there is a classical example that shows how inefficient recursion is by computing fibonacci numbers:
Code: Select all
function fib($number) {
if ($number <= 1)
return 1;
return fib($number - 1) + fib($number - 2);
}
this function is attrociacely inefficient, but using it to show that recursion is inefficient (believe it or not but some people actually did make this argument) is wrong.
[/go-on-soapbox]