-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Namespaced functions failing inside returned closure #78
Comments
FYI the real world scenario I've encountered this issue is attempting to meld It essentially plays pretty nicely - aside from this 1 issue. Here is a demo of this in action: https://github.com/brentkelly/serialized-promise-demo. You will see from the PR referenced in the README.md the exact lines in I was hoping to get them to work around the issue by referencing the full namespaced path on the function call but they're pushing back saying its a bug in |
@brentkelly instead of replacing every function call with the absolute form you could just import it once namespace My\Ns;
use function My\Ns\my_func; // reference my_func once instead of replacing every function call
$f = function() {
my_func();
// ...
my_func();
}; However a PR was submitted and probably this issue will be fixed in the next version. |
Great - thanks for the reply @sorinsarca :). Good suggestion re just using once - although still means I'd have to fork reactphp/promise. Look forward to the next version. |
@brentkelly this issue is fixed in version 3.5.7 of opis/closure |
@sorinsarca Brilliant - thanks! |
Hi guys - found a bit of a curly one.
TLDR; clone this repo & run
index.php
: https://github.com/brentkelly/opis-closure-bug-demo/Take the following scenario:
Call to undefined function
fatal error.Essentially - it loses track that the function call within the closure should be referencing the namespaced function - not the global scope. If you have a global function of the same name - it will call the global function instead of throwing the fatal error - producing potentially even more bizarre behavior :).
If you update the closure to instead reference the full function namespace path, everything then works smoothly.
Because there are a few moving parts, I've put together a quick repo demonstrating the behavior https://github.com/brentkelly/opis-closure-bug-demo/.
\Services\Foo
has methods that generate closures referencing the function\Services\foo()
(inside/services/functions.php
).index.php
creates a closure with a full namespace reference to\Services\foo()
and executes it, demonstrating it working fine.\Services
namespace, and executes it before & after serializing/unserializing.The last approch shows it execute fine prior to serializing, but after serialize/unserialize it throws:
Much respect for this project - its awesome.
The text was updated successfully, but these errors were encountered: