(Ditto remark here as the posting I just sent: Please direct any followup privately)
>From: "Stanislav Malyshev" <[EMAIL PROTECTED]> > TS>>An advantage of function objects in C++ is that they can be used where > TS>>functions are expected. Nevertheless, there are some features that can be > > Depending on what you mean of "expected". You can't use such object as a > function pointer, for example. Yes, you can write Object() and make that > do Object->operator(). In PHP that won't work, because $object() already > has meaning. Yup, that's one issue. > TS>>used to get something similar, such as create_function(): > > create_function is entirely different thing. It actually dynamically > creates a function (which C++ can't do) which you can call by name. Yes, but they are actually related (although I realise that wasn't clear from my post): Both function objects and dynamically created functions can be used as lambda/unnamed functions, for example for an algorithm. E.g (PHP): usort( $array, create_function('$a, $b', 'return $a->f() < $b->f()')); Yes, we can't create functions on-the-fly in C++ (at runtime), but we have something that can be used in much the same way, and it can also hold state (something you need to use function "static" or some such to do in PHP), function objects, and compile-time function object composition. With the Boost.Lambda library, you may actually do things like: sort(begin, end, _1 < _2); The last part creates a function object on the fly (at compile time), which performs comparison of the elements of the sequence ("begin" and "end" are iterators). > __call > handler is much more like - though not entirely - to the operator() concept. You can say that, but you might also say that it's somewhat similar to create_function(): It "creates" (the impression of a) member function at run time. ;) Regards, Terje -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php