-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Setting expose-global-functions
to false
breaks internal function calls
#960
Comments
expose-global-functions
to false
breaks internal function calls to functionsexpose-global-functions
to false
breaks internal function calls
I thought this was documented in https://github.com/humbug/php-scoper/blob/main/docs/limitations.md but apparently not. So I'll explain a bit more in details why it happens. The root of the issue, is not so much whether When PHP-Scoper comes in and scopes the So at the moment, it is unfortunately expected. THAT SAID. I'm wondering if there wouldn't be a way to handle it, for example PHP-Scoper could keep track of those ambiguous function calls, and if // for ambiguous `get_data` which could be `Illuminate\Support\Fluent\get_data` or `get_data`
// only when `expose-global-functions=false`
namespace Prefix\Illuminate\Support\Fluent;
if (!function_exists('Prefix\Illuminate\Support\Fluent\get_data') {
function get_data() { return \Prefix\get_data(...func_get_args()); }
} This way, if Would need to try out but on paper it should work |
The distinction between I'd love to see support for this, but I just just wanted to make sure I wasn't doing anything wrong. I was able to use a regex patch for the moment, but might move on to something like a custom php-parser script as a more long-term fix for this. I appreciate the detailed reply. |
After reviewing this, it does not make any sense. The reason being, this why |
Thanks for following up. I appreciate you taking another look. I was able to get things working and stable with a patch. |
Is it necessary to use a patch? Was using |
Using As an example, my scoped plugin calls the global |
I see, indeed it's a case for patchers then :/ Unless this could be patched in Laravel but I doubt think use statements for functions is a flavor liked by the maintainers |
Bug report
Thanks for building PHP Scoper. It's been a huge help over the last two years.
I'm running into some unexpected behavior when using PHP Scoper with
illuminate/support
and other similar packages. After scoping withexpose-global-functions
set tofalse
, I'm getting various errors about undefined functions.To set the stage,
illuminate/support
comes with helpers.php which contains some global function definitions. This are used in a few different places, but here's an example whereget_data
is used on line 50 of Fluent.php.In the example repo, I then make use of
Fluent
as seen below. Keep in mind this was just to demo the issue. The actual issue in the project I'm working on comes up after usingilluminate/database
to build some queries.The code above actually works just fine with PHP Scoper, but only with
expose-global-function
set totrue
. If I set it tofalse
, I get the following error:Looking at the scoped code, I saw that things were not lining up. In
helpers.php
the scope was added correctly (expandable below). InFluent.php
it was still callingdata_get
when it really needs to call\DEMO\data_get
.helpers.php after scoping
Fluent.php after scoping
Is this the expected behavior here? It's worth noting that if I manually change the calls in scoped code, it works perfectly fine. It's just not adding the scope to those global function calls when scoping them.
Thanks for taking the time to look into this one. I hope I provided enough details about the issue.
Here's a zip of the build after scoping the project with
expose-global-functions
set tofalse
:build.zip
scoper.inc.php
Output
The text was updated successfully, but these errors were encountered: