Re: closures questions

From: Date: Thu, 24 Jul 2008 09:10:10 +0000
Subject: Re: closures questions
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-39259@lists.php.net to get a copy of this message
Hi!
so do we even want the toString() method?
IMHO we should drop toString from Closure.
There is one case which *may* cause problems: function doSomething ($callback) { if (!is_callable ($callback)) {
    throw new Exception (...);
} // special treatment if ($callback == 'default') {
    ...
} else {
    ...
} } Here, the comparison of $callback with 'default' will yield a notice that $callback couldn't be converted. The comparison will fail correctly, of course, but it could cause some confusion. The correct way of comparing would obviously be using ===, that won't cause these hickups. Personally, I don't care whether a object-to-string cast is present or not.
I don't think Closure can be meaningfully exported. Can we prohibit it?
Unfortunately, currently not, see the var_export code.
I think we can make working clone there - just copy all data, etc.
Perhaps. But I'd recommend this should be postponed, as there are quite a few subtleties regarding semantics of bound variables involved. Should there seem to be a strong need for cloning closures by the community, this can always be implemented in a future PHP version. IMHO. Regards, Christian

« previous php.internals (#39259) next »